

<!DOCTYPE html>

<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>User Guide for AMDGPU Backend &#8212; LLVM 9 documentation</title>
    <link rel="stylesheet" href="_static/llvm-theme.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    <script id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
    <script src="_static/jquery.js"></script>
    <script src="_static/underscore.js"></script>
    <script src="_static/doctools.js"></script>
    <script src="_static/language_data.js"></script>
    <link rel="index" title="Index" href="genindex.html" />
    <link rel="search" title="Search" href="search.html" />
    <link rel="next" title="Syntax of GFX7 Instructions" href="AMDGPU/AMDGPUAsmGFX7.html" />
    <link rel="prev" title="User Guide for NVPTX Back-end" href="NVPTXUsage.html" />
<style type="text/css">
  table.right { float: right; margin-left: 20px; }
  table.right td { border: 1px solid #ccc; }
</style>

  </head><body>
<div class="logo">
  <a href="index.html">
    <img src="_static/logo.png"
         alt="LLVM Logo" width="250" height="88"/></a>
</div>

    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="AMDGPU/AMDGPUAsmGFX7.html" title="Syntax of GFX7 Instructions"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="NVPTXUsage.html" title="User Guide for NVPTX Back-end"
             accesskey="P">previous</a> |</li>
  <li><a href="http://llvm.org/">LLVM Home</a>&nbsp;|&nbsp;</li>
  <li><a href="index.html">Documentation</a>&raquo;</li>

        <li class="nav-item nav-item-this"><a href="">User Guide for AMDGPU Backend</a></li> 
      </ul>
    </div>


    <div class="document">
      <div class="documentwrapper">
          <div class="body" role="main">
            
  <div class="section" id="user-guide-for-amdgpu-backend">
<h1>User Guide for AMDGPU Backend<a class="headerlink" href="#user-guide-for-amdgpu-backend" title="Permalink to this headline">¶</a></h1>
<div class="contents local topic" id="contents">
<ul class="simple">
<li><p><a class="reference internal" href="#introduction" id="id48">Introduction</a></p></li>
<li><p><a class="reference internal" href="#llvm" id="id49">LLVM</a></p>
<ul>
<li><p><a class="reference internal" href="#target-triples" id="id50">Target Triples</a></p></li>
<li><p><a class="reference internal" href="#processors" id="id51">Processors</a></p></li>
<li><p><a class="reference internal" href="#target-features" id="id52">Target Features</a></p></li>
<li><p><a class="reference internal" href="#address-spaces" id="id53">Address Spaces</a></p></li>
<li><p><a class="reference internal" href="#memory-scopes" id="id54">Memory Scopes</a></p></li>
<li><p><a class="reference internal" href="#amdgpu-intrinsics" id="id55">AMDGPU Intrinsics</a></p></li>
<li><p><a class="reference internal" href="#amdgpu-attributes" id="id56">AMDGPU Attributes</a></p></li>
</ul>
</li>
<li><p><a class="reference internal" href="#code-object" id="id57">Code Object</a></p>
<ul>
<li><p><a class="reference internal" href="#header" id="id58">Header</a></p></li>
<li><p><a class="reference internal" href="#sections" id="id59">Sections</a></p></li>
<li><p><a class="reference internal" href="#note-records" id="id60">Note Records</a></p>
<ul>
<li><p><a class="reference internal" href="#code-object-v2-note-records-mattr-code-object-v3" id="id61">Code Object V2 Note Records (-mattr=-code-object-v3)</a></p></li>
<li><p><a class="reference internal" href="#code-object-v3-note-records-mattr-code-object-v3" id="id62">Code Object V3 Note Records (-mattr=+code-object-v3)</a></p></li>
</ul>
</li>
<li><p><a class="reference internal" href="#symbols" id="id63">Symbols</a></p></li>
<li><p><a class="reference internal" href="#relocation-records" id="id64">Relocation Records</a></p></li>
<li><p><a class="reference internal" href="#dwarf" id="id65">DWARF</a></p>
<ul>
<li><p><a class="reference internal" href="#address-space-mapping" id="id66">Address Space Mapping</a></p></li>
<li><p><a class="reference internal" href="#register-mapping" id="id67">Register Mapping</a></p></li>
<li><p><a class="reference internal" href="#source-text" id="id68">Source Text</a></p></li>
</ul>
</li>
</ul>
</li>
<li><p><a class="reference internal" href="#code-conventions" id="id69">Code Conventions</a></p>
<ul>
<li><p><a class="reference internal" href="#amdhsa" id="id70">AMDHSA</a></p>
<ul>
<li><p><a class="reference internal" href="#code-object-target-identification" id="id71">Code Object Target Identification</a></p></li>
<li><p><a class="reference internal" href="#code-object-metadata" id="id72">Code Object Metadata</a></p>
<ul>
<li><p><a class="reference internal" href="#code-object-v2-metadata-mattr-code-object-v3" id="id73">Code Object V2 Metadata (-mattr=-code-object-v3)</a></p></li>
<li><p><a class="reference internal" href="#code-object-v3-metadata-mattr-code-object-v3" id="id74">Code Object V3 Metadata (-mattr=+code-object-v3)</a></p></li>
</ul>
</li>
<li><p><a class="reference internal" href="#kernel-dispatch" id="id75">Kernel Dispatch</a></p></li>
<li><p><a class="reference internal" href="#memory-spaces" id="id76">Memory Spaces</a></p></li>
<li><p><a class="reference internal" href="#image-and-samplers" id="id77">Image and Samplers</a></p></li>
<li><p><a class="reference internal" href="#hsa-signals" id="id78">HSA Signals</a></p></li>
<li><p><a class="reference internal" href="#hsa-aql-queue" id="id79">HSA AQL Queue</a></p></li>
<li><p><a class="reference internal" href="#kernel-descriptor" id="id80">Kernel Descriptor</a></p>
<ul>
<li><p><a class="reference internal" href="#kernel-descriptor-for-gfx6-gfx10" id="id81">Kernel Descriptor for GFX6-GFX10</a></p></li>
</ul>
</li>
<li><p><a class="reference internal" href="#initial-kernel-execution-state" id="id82">Initial Kernel Execution State</a></p></li>
<li><p><a class="reference internal" href="#kernel-prolog" id="id83">Kernel Prolog</a></p>
<ul>
<li><p><a class="reference internal" href="#m0" id="id84">M0</a></p></li>
<li><p><a class="reference internal" href="#flat-scratch" id="id85">Flat Scratch</a></p></li>
</ul>
</li>
<li><p><a class="reference internal" href="#memory-model" id="id86">Memory Model</a></p></li>
<li><p><a class="reference internal" href="#trap-handler-abi" id="id87">Trap Handler ABI</a></p></li>
</ul>
</li>
<li><p><a class="reference internal" href="#amdpal" id="id88">AMDPAL</a></p>
<ul>
<li><p><a class="reference internal" href="#user-data" id="id89">User Data</a></p></li>
<li><p><a class="reference internal" href="#compute-user-data" id="id90">Compute User Data</a></p></li>
<li><p><a class="reference internal" href="#graphics-user-data" id="id91">Graphics User Data</a></p></li>
<li><p><a class="reference internal" href="#global-internal-table" id="id92">Global Internal Table</a></p></li>
</ul>
</li>
<li><p><a class="reference internal" href="#unspecified-os" id="id93">Unspecified OS</a></p>
<ul>
<li><p><a class="reference internal" href="#id39" id="id94">Trap Handler ABI</a></p></li>
</ul>
</li>
</ul>
</li>
<li><p><a class="reference internal" href="#source-languages" id="id95">Source Languages</a></p>
<ul>
<li><p><a class="reference internal" href="#opencl" id="id96">OpenCL</a></p></li>
<li><p><a class="reference internal" href="#hcc" id="id97">HCC</a></p></li>
<li><p><a class="reference internal" href="#assembler" id="id98">Assembler</a></p>
<ul>
<li><p><a class="reference internal" href="#instructions" id="id99">Instructions</a></p></li>
<li><p><a class="reference internal" href="#operands" id="id100">Operands</a></p></li>
<li><p><a class="reference internal" href="#modifiers" id="id101">Modifiers</a></p></li>
<li><p><a class="reference internal" href="#instruction-examples" id="id102">Instruction Examples</a></p>
<ul>
<li><p><a class="reference internal" href="#ds" id="id103">DS</a></p></li>
<li><p><a class="reference internal" href="#flat" id="id104">FLAT</a></p></li>
<li><p><a class="reference internal" href="#mubuf" id="id105">MUBUF</a></p></li>
<li><p><a class="reference internal" href="#smrd-smem" id="id106">SMRD/SMEM</a></p></li>
<li><p><a class="reference internal" href="#sop1" id="id107">SOP1</a></p></li>
<li><p><a class="reference internal" href="#sop2" id="id108">SOP2</a></p></li>
<li><p><a class="reference internal" href="#sopc" id="id109">SOPC</a></p></li>
<li><p><a class="reference internal" href="#sopp" id="id110">SOPP</a></p></li>
<li><p><a class="reference internal" href="#valu" id="id111">VALU</a></p></li>
</ul>
</li>
<li><p><a class="reference internal" href="#code-object-v2-predefined-symbols-mattr-code-object-v3" id="id112">Code Object V2 Predefined Symbols (-mattr=-code-object-v3)</a></p>
<ul>
<li><p><a class="reference internal" href="#option-machine-version-major" id="id113">.option.machine_version_major</a></p></li>
<li><p><a class="reference internal" href="#option-machine-version-minor" id="id114">.option.machine_version_minor</a></p></li>
<li><p><a class="reference internal" href="#option-machine-version-stepping" id="id115">.option.machine_version_stepping</a></p></li>
<li><p><a class="reference internal" href="#kernel-vgpr-count" id="id116">.kernel.vgpr_count</a></p></li>
<li><p><a class="reference internal" href="#kernel-sgpr-count" id="id117">.kernel.sgpr_count</a></p></li>
</ul>
</li>
<li><p><a class="reference internal" href="#code-object-v2-directives-mattr-code-object-v3" id="id118">Code Object V2 Directives (-mattr=-code-object-v3)</a></p>
<ul>
<li><p><a class="reference internal" href="#hsa-code-object-version-major-minor" id="id119">.hsa_code_object_version major, minor</a></p></li>
<li><p><a class="reference internal" href="#hsa-code-object-isa-major-minor-stepping-vendor-arch" id="id120">.hsa_code_object_isa [major, minor, stepping, vendor, arch]</a></p></li>
<li><p><a class="reference internal" href="#amdgpu-hsa-kernel-name" id="id121">.amdgpu_hsa_kernel (name)</a></p></li>
<li><p><a class="reference internal" href="#amd-kernel-code-t" id="id122">.amd_kernel_code_t</a></p></li>
</ul>
</li>
<li><p><a class="reference internal" href="#code-object-v2-example-source-code-mattr-code-object-v3" id="id123">Code Object V2 Example Source Code (-mattr=-code-object-v3)</a></p></li>
<li><p><a class="reference internal" href="#code-object-v3-predefined-symbols-mattr-code-object-v3" id="id124">Code Object V3 Predefined Symbols (-mattr=+code-object-v3)</a></p>
<ul>
<li><p><a class="reference internal" href="#amdgcn-gfx-generation-number" id="id125">.amdgcn.gfx_generation_number</a></p></li>
<li><p><a class="reference internal" href="#amdgcn-gfx-generation-minor" id="id126">.amdgcn.gfx_generation_minor</a></p></li>
<li><p><a class="reference internal" href="#amdgcn-gfx-generation-stepping" id="id127">.amdgcn.gfx_generation_stepping</a></p></li>
<li><p><a class="reference internal" href="#amdgcn-next-free-vgpr" id="id128">.amdgcn.next_free_vgpr</a></p></li>
<li><p><a class="reference internal" href="#amdgcn-next-free-sgpr" id="id129">.amdgcn.next_free_sgpr</a></p></li>
</ul>
</li>
<li><p><a class="reference internal" href="#code-object-v3-directives-mattr-code-object-v3" id="id130">Code Object V3 Directives (-mattr=+code-object-v3)</a></p>
<ul>
<li><p><a class="reference internal" href="#amdgcn-target-target" id="id131">.amdgcn_target &lt;target&gt;</a></p></li>
<li><p><a class="reference internal" href="#amdhsa-kernel-name" id="id132">.amdhsa_kernel &lt;name&gt;</a></p></li>
<li><p><a class="reference internal" href="#amdgpu-metadata" id="id133">.amdgpu_metadata</a></p></li>
</ul>
</li>
<li><p><a class="reference internal" href="#code-object-v3-example-source-code-mattr-code-object-v3" id="id134">Code Object V3 Example Source Code (-mattr=+code-object-v3)</a></p></li>
</ul>
</li>
</ul>
</li>
<li><p><a class="reference internal" href="#additional-documentation" id="id135">Additional Documentation</a></p></li>
</ul>
</div>
<div class="section" id="introduction">
<h2><a class="toc-backref" href="#id48">Introduction</a><a class="headerlink" href="#introduction" title="Permalink to this headline">¶</a></h2>
<p>The AMDGPU backend provides ISA code generation for AMD GPUs, starting with the
R600 family up until the current GCN families. It lives in the
<code class="docutils literal notranslate"><span class="pre">lib/Target/AMDGPU</span></code> directory.</p>
</div>
<div class="section" id="llvm">
<h2><a class="toc-backref" href="#id49">LLVM</a><a class="headerlink" href="#llvm" title="Permalink to this headline">¶</a></h2>
<div class="section" id="target-triples">
<span id="amdgpu-target-triples"></span><h3><a class="toc-backref" href="#id50">Target Triples</a><a class="headerlink" href="#target-triples" title="Permalink to this headline">¶</a></h3>
<p>Use the <code class="docutils literal notranslate"><span class="pre">clang</span> <span class="pre">-target</span> <span class="pre">&lt;Architecture&gt;-&lt;Vendor&gt;-&lt;OS&gt;-&lt;Environment&gt;</span></code> option to
specify the target triple:</p>
<blockquote>
<div><table class="docutils align-default" id="amdgpu-architecture-table">
<caption><span class="caption-text">AMDGPU Architectures</span><a class="headerlink" href="#amdgpu-architecture-table" title="Permalink to this table">¶</a></caption>
<colgroup>
<col style="width: 16%" />
<col style="width: 84%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>Architecture</p></th>
<th class="head"><p>Description</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">r600</span></code></p></td>
<td><p>AMD GPUs HD2XXX-HD6XXX for graphics and compute shaders.</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">amdgcn</span></code></p></td>
<td><p>AMD GPUs GCN GFX6 onwards for graphics and compute shaders.</p></td>
</tr>
</tbody>
</table>
<table class="docutils align-default" id="amdgpu-vendor-table">
<caption><span class="caption-text">AMDGPU Vendors</span><a class="headerlink" href="#amdgpu-vendor-table" title="Permalink to this table">¶</a></caption>
<colgroup>
<col style="width: 16%" />
<col style="width: 84%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>Vendor</p></th>
<th class="head"><p>Description</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">amd</span></code></p></td>
<td><p>Can be used for all AMD GPU usage.</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">mesa3d</span></code></p></td>
<td><p>Can be used if the OS is <code class="docutils literal notranslate"><span class="pre">mesa3d</span></code>.</p></td>
</tr>
</tbody>
</table>
<table class="docutils align-default" id="amdgpu-os-table">
<caption><span class="caption-text">AMDGPU Operating Systems</span><a class="headerlink" href="#amdgpu-os-table" title="Permalink to this table">¶</a></caption>
<colgroup>
<col style="width: 19%" />
<col style="width: 81%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>OS</p></th>
<th class="head"><p>Description</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p><em>&lt;empty&gt;</em></p></td>
<td><p>Defaults to the <em>unknown</em> OS.</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">amdhsa</span></code></p></td>
<td><p>Compute kernels executed on HSA <a class="reference internal" href="#hsa" id="id1"><span>[HSA]</span></a> compatible runtimes
such as AMD’s ROCm <a class="reference internal" href="#amd-rocm" id="id2"><span>[AMD-ROCm]</span></a>.</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">amdpal</span></code></p></td>
<td><p>Graphic shaders and compute kernels executed on AMD PAL
runtime.</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">mesa3d</span></code></p></td>
<td><p>Graphic shaders and compute kernels executed on Mesa 3D
runtime.</p></td>
</tr>
</tbody>
</table>
<table class="docutils align-default" id="amdgpu-environment-table">
<caption><span class="caption-text">AMDGPU Environments</span><a class="headerlink" href="#amdgpu-environment-table" title="Permalink to this table">¶</a></caption>
<colgroup>
<col style="width: 16%" />
<col style="width: 84%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>Environment</p></th>
<th class="head"><p>Description</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p><em>&lt;empty&gt;</em></p></td>
<td><p>Default.</p></td>
</tr>
</tbody>
</table>
</div></blockquote>
</div>
<div class="section" id="processors">
<span id="amdgpu-processors"></span><h3><a class="toc-backref" href="#id51">Processors</a><a class="headerlink" href="#processors" title="Permalink to this headline">¶</a></h3>
<p>Use the <code class="docutils literal notranslate"><span class="pre">clang</span> <span class="pre">-mcpu</span> <span class="pre">&lt;Processor&gt;</span></code> option to specify the AMD GPU processor. The
names from both the <em>Processor</em> and <em>Alternative Processor</em> can be used.</p>
<blockquote>
<div><table class="docutils align-default" id="amdgpu-processor-table">
<caption><span class="caption-text">AMDGPU Processors</span><a class="headerlink" href="#amdgpu-processor-table" title="Permalink to this table">¶</a></caption>
<colgroup>
<col style="width: 12%" />
<col style="width: 17%" />
<col style="width: 13%" />
<col style="width: 6%" />
<col style="width: 19%" />
<col style="width: 8%" />
<col style="width: 25%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>Processor</p></th>
<th class="head"><p>Alternative
Processor</p></th>
<th class="head"><p>Target
Triple
Architecture</p></th>
<th class="head"><p>dGPU/
APU</p></th>
<th class="head"><p>Target
Features
Supported
[Default]</p></th>
<th class="head"><p>ROCm
Support</p></th>
<th class="head"><p>Example
Products</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td colspan="7"><p><strong>Radeon HD 2000/3000 Series (R600)</strong> <a class="reference internal" href="#amd-radeon-hd-2000-3000" id="id3"><span>[AMD-RADEON-HD-2000-3000]</span></a></p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">r600</span></code></p></td>
<td></td>
<td><p><code class="docutils literal notranslate"><span class="pre">r600</span></code></p></td>
<td><p>dGPU</p></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">r630</span></code></p></td>
<td></td>
<td><p><code class="docutils literal notranslate"><span class="pre">r600</span></code></p></td>
<td><p>dGPU</p></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">rs880</span></code></p></td>
<td></td>
<td><p><code class="docutils literal notranslate"><span class="pre">r600</span></code></p></td>
<td><p>dGPU</p></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">rv670</span></code></p></td>
<td></td>
<td><p><code class="docutils literal notranslate"><span class="pre">r600</span></code></p></td>
<td><p>dGPU</p></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr class="row-odd"><td colspan="7"><p><strong>Radeon HD 4000 Series (R700)</strong> <a class="reference internal" href="#amd-radeon-hd-4000" id="id4"><span>[AMD-RADEON-HD-4000]</span></a></p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">rv710</span></code></p></td>
<td></td>
<td><p><code class="docutils literal notranslate"><span class="pre">r600</span></code></p></td>
<td><p>dGPU</p></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">rv730</span></code></p></td>
<td></td>
<td><p><code class="docutils literal notranslate"><span class="pre">r600</span></code></p></td>
<td><p>dGPU</p></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">rv770</span></code></p></td>
<td></td>
<td><p><code class="docutils literal notranslate"><span class="pre">r600</span></code></p></td>
<td><p>dGPU</p></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr class="row-odd"><td colspan="7"><p><strong>Radeon HD 5000 Series (Evergreen)</strong> <a class="reference internal" href="#amd-radeon-hd-5000" id="id5"><span>[AMD-RADEON-HD-5000]</span></a></p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">cedar</span></code></p></td>
<td></td>
<td><p><code class="docutils literal notranslate"><span class="pre">r600</span></code></p></td>
<td><p>dGPU</p></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">cypress</span></code></p></td>
<td></td>
<td><p><code class="docutils literal notranslate"><span class="pre">r600</span></code></p></td>
<td><p>dGPU</p></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">juniper</span></code></p></td>
<td></td>
<td><p><code class="docutils literal notranslate"><span class="pre">r600</span></code></p></td>
<td><p>dGPU</p></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">redwood</span></code></p></td>
<td></td>
<td><p><code class="docutils literal notranslate"><span class="pre">r600</span></code></p></td>
<td><p>dGPU</p></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">sumo</span></code></p></td>
<td></td>
<td><p><code class="docutils literal notranslate"><span class="pre">r600</span></code></p></td>
<td><p>dGPU</p></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr class="row-odd"><td colspan="7"><p><strong>Radeon HD 6000 Series (Northern Islands)</strong> <a class="reference internal" href="#amd-radeon-hd-6000" id="id6"><span>[AMD-RADEON-HD-6000]</span></a></p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">barts</span></code></p></td>
<td></td>
<td><p><code class="docutils literal notranslate"><span class="pre">r600</span></code></p></td>
<td><p>dGPU</p></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">caicos</span></code></p></td>
<td></td>
<td><p><code class="docutils literal notranslate"><span class="pre">r600</span></code></p></td>
<td><p>dGPU</p></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">cayman</span></code></p></td>
<td></td>
<td><p><code class="docutils literal notranslate"><span class="pre">r600</span></code></p></td>
<td><p>dGPU</p></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">turks</span></code></p></td>
<td></td>
<td><p><code class="docutils literal notranslate"><span class="pre">r600</span></code></p></td>
<td><p>dGPU</p></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr class="row-even"><td colspan="7"><p><strong>GCN GFX6 (Southern Islands (SI))</strong> <a class="reference internal" href="#amd-gcn-gfx6" id="id7"><span>[AMD-GCN-GFX6]</span></a></p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">gfx600</span></code></p></td>
<td><ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">tahiti</span></code></p></li>
</ul>
</td>
<td><p><code class="docutils literal notranslate"><span class="pre">amdgcn</span></code></p></td>
<td><p>dGPU</p></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">gfx601</span></code></p></td>
<td><ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">hainan</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">oland</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">pitcairn</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">verde</span></code></p></li>
</ul>
</td>
<td><p><code class="docutils literal notranslate"><span class="pre">amdgcn</span></code></p></td>
<td><p>dGPU</p></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr class="row-odd"><td colspan="7"><p><strong>GCN GFX7 (Sea Islands (CI))</strong> <a class="reference internal" href="#amd-gcn-gfx7" id="id8"><span>[AMD-GCN-GFX7]</span></a></p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">gfx700</span></code></p></td>
<td><ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">kaveri</span></code></p></li>
</ul>
</td>
<td><p><code class="docutils literal notranslate"><span class="pre">amdgcn</span></code></p></td>
<td><p>APU</p></td>
<td></td>
<td></td>
<td><ul class="simple">
<li><p>A6-7000</p></li>
<li><p>A6 Pro-7050B</p></li>
<li><p>A8-7100</p></li>
<li><p>A8 Pro-7150B</p></li>
<li><p>A10-7300</p></li>
<li><p>A10 Pro-7350B</p></li>
<li><p>FX-7500</p></li>
<li><p>A8-7200P</p></li>
<li><p>A10-7400P</p></li>
<li><p>FX-7600P</p></li>
</ul>
</td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">gfx701</span></code></p></td>
<td><ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">hawaii</span></code></p></li>
</ul>
</td>
<td><p><code class="docutils literal notranslate"><span class="pre">amdgcn</span></code></p></td>
<td><p>dGPU</p></td>
<td></td>
<td><p>ROCm</p></td>
<td><ul class="simple">
<li><p>FirePro W8100</p></li>
<li><p>FirePro W9100</p></li>
<li><p>FirePro S9150</p></li>
<li><p>FirePro S9170</p></li>
</ul>
</td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">gfx702</span></code></p></td>
<td></td>
<td><p><code class="docutils literal notranslate"><span class="pre">amdgcn</span></code></p></td>
<td><p>dGPU</p></td>
<td></td>
<td><p>ROCm</p></td>
<td><ul class="simple">
<li><p>Radeon R9 290</p></li>
<li><p>Radeon R9 290x</p></li>
<li><p>Radeon R390</p></li>
<li><p>Radeon R390x</p></li>
</ul>
</td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">gfx703</span></code></p></td>
<td><ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">kabini</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">mullins</span></code></p></li>
</ul>
</td>
<td><p><code class="docutils literal notranslate"><span class="pre">amdgcn</span></code></p></td>
<td><p>APU</p></td>
<td></td>
<td></td>
<td><ul class="simple">
<li><p>E1-2100</p></li>
<li><p>E1-2200</p></li>
<li><p>E1-2500</p></li>
<li><p>E2-3000</p></li>
<li><p>E2-3800</p></li>
<li><p>A4-5000</p></li>
<li><p>A4-5100</p></li>
<li><p>A6-5200</p></li>
<li><p>A4 Pro-3340B</p></li>
</ul>
</td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">gfx704</span></code></p></td>
<td><ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">bonaire</span></code></p></li>
</ul>
</td>
<td><p><code class="docutils literal notranslate"><span class="pre">amdgcn</span></code></p></td>
<td><p>dGPU</p></td>
<td></td>
<td></td>
<td><ul class="simple">
<li><p>Radeon HD 7790</p></li>
<li><p>Radeon HD 8770</p></li>
<li><p>R7 260</p></li>
<li><p>R7 260X</p></li>
</ul>
</td>
</tr>
<tr class="row-odd"><td colspan="7"><p><strong>GCN GFX8 (Volcanic Islands (VI))</strong> <a class="reference internal" href="#amd-gcn-gfx8" id="id9"><span>[AMD-GCN-GFX8]</span></a></p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">gfx801</span></code></p></td>
<td><ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">carrizo</span></code></p></li>
</ul>
</td>
<td><p><code class="docutils literal notranslate"><span class="pre">amdgcn</span></code></p></td>
<td><p>APU</p></td>
<td><ul class="simple">
<li><p>xnack
[on]</p></li>
</ul>
</td>
<td></td>
<td><ul class="simple">
<li><p>A6-8500P</p></li>
<li><p>Pro A6-8500B</p></li>
<li><p>A8-8600P</p></li>
<li><p>Pro A8-8600B</p></li>
<li><p>FX-8800P</p></li>
<li><p>Pro A12-8800B</p></li>
</ul>
</td>
</tr>
<tr class="row-odd"><td><p></p></td>
<td></td>
<td><p><code class="docutils literal notranslate"><span class="pre">amdgcn</span></code></p></td>
<td><p>APU</p></td>
<td><ul class="simple">
<li><p>xnack
[on]</p></li>
</ul>
</td>
<td><p>ROCm</p></td>
<td><ul class="simple">
<li><p>A10-8700P</p></li>
<li><p>Pro A10-8700B</p></li>
<li><p>A10-8780P</p></li>
</ul>
</td>
</tr>
<tr class="row-even"><td><p></p></td>
<td></td>
<td><p><code class="docutils literal notranslate"><span class="pre">amdgcn</span></code></p></td>
<td><p>APU</p></td>
<td><ul class="simple">
<li><p>xnack
[on]</p></li>
</ul>
</td>
<td></td>
<td><ul class="simple">
<li><p>A10-9600P</p></li>
<li><p>A10-9630P</p></li>
<li><p>A12-9700P</p></li>
<li><p>A12-9730P</p></li>
<li><p>FX-9800P</p></li>
<li><p>FX-9830P</p></li>
</ul>
</td>
</tr>
<tr class="row-odd"><td><p></p></td>
<td></td>
<td><p><code class="docutils literal notranslate"><span class="pre">amdgcn</span></code></p></td>
<td><p>APU</p></td>
<td><ul class="simple">
<li><p>xnack
[on]</p></li>
</ul>
</td>
<td></td>
<td><ul class="simple">
<li><p>E2-9010</p></li>
<li><p>A6-9210</p></li>
<li><p>A9-9410</p></li>
</ul>
</td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">gfx802</span></code></p></td>
<td><ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">iceland</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">tonga</span></code></p></li>
</ul>
</td>
<td><p><code class="docutils literal notranslate"><span class="pre">amdgcn</span></code></p></td>
<td><p>dGPU</p></td>
<td><ul class="simple">
<li><p>xnack
[off]</p></li>
</ul>
</td>
<td><p>ROCm</p></td>
<td><ul class="simple">
<li><p>FirePro S7150</p></li>
<li><p>FirePro S7100</p></li>
<li><p>FirePro W7100</p></li>
<li><p>Radeon R285</p></li>
<li><p>Radeon R9 380</p></li>
<li><p>Radeon R9 385</p></li>
<li><p>Mobile FirePro
M7170</p></li>
</ul>
</td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">gfx803</span></code></p></td>
<td><ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">fiji</span></code></p></li>
</ul>
</td>
<td><p><code class="docutils literal notranslate"><span class="pre">amdgcn</span></code></p></td>
<td><p>dGPU</p></td>
<td><ul class="simple">
<li><p>xnack
[off]</p></li>
</ul>
</td>
<td><p>ROCm</p></td>
<td><ul class="simple">
<li><p>Radeon R9 Nano</p></li>
<li><p>Radeon R9 Fury</p></li>
<li><p>Radeon R9 FuryX</p></li>
<li><p>Radeon Pro Duo</p></li>
<li><p>FirePro S9300x2</p></li>
<li><p>Radeon Instinct MI8</p></li>
</ul>
</td>
</tr>
<tr class="row-even"><td><p></p></td>
<td><ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">polaris10</span></code></p></li>
</ul>
</td>
<td><p><code class="docutils literal notranslate"><span class="pre">amdgcn</span></code></p></td>
<td><p>dGPU</p></td>
<td><ul class="simple">
<li><p>xnack
[off]</p></li>
</ul>
</td>
<td><p>ROCm</p></td>
<td><ul class="simple">
<li><p>Radeon RX 470</p></li>
<li><p>Radeon RX 480</p></li>
<li><p>Radeon Instinct MI6</p></li>
</ul>
</td>
</tr>
<tr class="row-odd"><td><p></p></td>
<td><ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">polaris11</span></code></p></li>
</ul>
</td>
<td><p><code class="docutils literal notranslate"><span class="pre">amdgcn</span></code></p></td>
<td><p>dGPU</p></td>
<td><ul class="simple">
<li><p>xnack
[off]</p></li>
</ul>
</td>
<td><p>ROCm</p></td>
<td><ul class="simple">
<li><p>Radeon RX 460</p></li>
</ul>
</td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">gfx810</span></code></p></td>
<td><ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">stoney</span></code></p></li>
</ul>
</td>
<td><p><code class="docutils literal notranslate"><span class="pre">amdgcn</span></code></p></td>
<td><p>APU</p></td>
<td><ul class="simple">
<li><p>xnack
[on]</p></li>
</ul>
</td>
<td></td>
<td></td>
</tr>
<tr class="row-odd"><td colspan="7"><p><strong>GCN GFX9</strong> <a class="reference internal" href="#amd-gcn-gfx9" id="id10"><span>[AMD-GCN-GFX9]</span></a></p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">gfx900</span></code></p></td>
<td></td>
<td><p><code class="docutils literal notranslate"><span class="pre">amdgcn</span></code></p></td>
<td><p>dGPU</p></td>
<td><ul class="simple">
<li><p>xnack
[off]</p></li>
</ul>
</td>
<td><p>ROCm</p></td>
<td><ul class="simple">
<li><p>Radeon Vega
Frontier Edition</p></li>
<li><p>Radeon RX Vega 56</p></li>
<li><p>Radeon RX Vega 64</p></li>
<li><p>Radeon RX Vega 64
Liquid</p></li>
<li><p>Radeon Instinct MI25</p></li>
</ul>
</td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">gfx902</span></code></p></td>
<td></td>
<td><p><code class="docutils literal notranslate"><span class="pre">amdgcn</span></code></p></td>
<td><p>APU</p></td>
<td><ul class="simple">
<li><p>xnack
[on]</p></li>
</ul>
</td>
<td></td>
<td><ul class="simple">
<li><p>Ryzen 3 2200G</p></li>
<li><p>Ryzen 5 2400G</p></li>
</ul>
</td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">gfx904</span></code></p></td>
<td></td>
<td><p><code class="docutils literal notranslate"><span class="pre">amdgcn</span></code></p></td>
<td><p>dGPU</p></td>
<td><ul class="simple">
<li><p>xnack
[off]</p></li>
</ul>
</td>
<td></td>
<td><p><em>TBA</em></p>
</td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">gfx906</span></code></p></td>
<td></td>
<td><p><code class="docutils literal notranslate"><span class="pre">amdgcn</span></code></p></td>
<td><p>dGPU</p></td>
<td><ul class="simple">
<li><p>xnack
[off]</p></li>
</ul>
</td>
<td></td>
<td><ul class="simple">
<li><p>Radeon Instinct MI50</p></li>
<li><p>Radeon Instinct MI60</p></li>
</ul>
</td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">gfx908</span></code></p></td>
<td></td>
<td><p><code class="docutils literal notranslate"><span class="pre">amdgcn</span></code></p></td>
<td><p>dGPU</p></td>
<td><ul class="simple">
<li><p>xnack
[off]
sram-ecc
[on]</p></li>
</ul>
</td>
<td></td>
<td><p><em>TBA</em></p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">gfx909</span></code></p></td>
<td></td>
<td><p><code class="docutils literal notranslate"><span class="pre">amdgcn</span></code></p></td>
<td><p>APU</p></td>
<td><ul class="simple">
<li><p>xnack
[on]</p></li>
</ul>
</td>
<td></td>
<td><p><em>TBA</em> (Raven Ridge 2)</p>
</td>
</tr>
<tr class="row-even"><td colspan="7"><p><strong>GCN GFX10</strong> <a class="reference internal" href="#amd-gcn-gfx10" id="id11"><span>[AMD-GCN-GFX10]</span></a></p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">gfx1010</span></code></p></td>
<td></td>
<td><p><code class="docutils literal notranslate"><span class="pre">amdgcn</span></code></p></td>
<td><p>dGPU</p></td>
<td><ul class="simple">
<li><p>xnack
[off]</p></li>
<li><p>wavefrontsize64
[off]</p></li>
<li><p>cumode
[off]</p></li>
</ul>
</td>
<td></td>
<td><p><em>TBA</em></p>
</td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">gfx1011</span></code></p></td>
<td></td>
<td><p><code class="docutils literal notranslate"><span class="pre">amdgcn</span></code></p></td>
<td><p>dGPU</p></td>
<td><ul class="simple">
<li><p>xnack
[off]</p></li>
<li><p>wavefrontsize64
[off]</p></li>
<li><p>cumode
[off]</p></li>
</ul>
</td>
<td></td>
<td><p><em>TBA</em></p>
</td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">gfx1012</span></code></p></td>
<td></td>
<td><p><code class="docutils literal notranslate"><span class="pre">amdgcn</span></code></p></td>
<td><p>dGPU</p></td>
<td><ul class="simple">
<li><p>xnack
[off]</p></li>
<li><p>wavefrontsize64
[off]</p></li>
<li><p>cumode
[off]</p></li>
</ul>
</td>
<td></td>
<td><p><em>TBA</em></p>
</td>
</tr>
</tbody>
</table>
</div></blockquote>
</div>
<div class="section" id="target-features">
<span id="amdgpu-target-features"></span><h3><a class="toc-backref" href="#id52">Target Features</a><a class="headerlink" href="#target-features" title="Permalink to this headline">¶</a></h3>
<p>Target features control how code is generated to support certain
processor specific features. Not all target features are supported by
all processors. The runtime must ensure that the features supported by
the device used to execute the code match the features enabled when
generating the code. A mismatch of features may result in incorrect
execution, or a reduction in performance.</p>
<p>The target features supported by each processor, and the default value
used if not specified explicitly, is listed in
<a class="reference internal" href="#amdgpu-processor-table"><span class="std std-ref">AMDGPU Processors</span></a>.</p>
<p>Use the <code class="docutils literal notranslate"><span class="pre">clang</span> <span class="pre">-m[no-]&lt;TargetFeature&gt;</span></code> option to specify the AMD GPU
target features.</p>
<p>For example:</p>
<dl>
<dt><code class="docutils literal notranslate"><span class="pre">-mxnack</span></code></dt><dd><p>Enable the <code class="docutils literal notranslate"><span class="pre">xnack</span></code> feature.</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">-mno-xnack</span></code></dt><dd><p>Disable the <code class="docutils literal notranslate"><span class="pre">xnack</span></code> feature.</p>
<table class="docutils align-default" id="amdgpu-target-feature-table">
<caption><span class="caption-text">AMDGPU Target Features</span><a class="headerlink" href="#amdgpu-target-feature-table" title="Permalink to this table">¶</a></caption>
<colgroup>
<col style="width: 31%" />
<col style="width: 69%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>Target Feature</p></th>
<th class="head"><p>Description</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>-m[no-]xnack</p></td>
<td><p>Enable/disable generating code that has
memory clauses that are compatible with
having XNACK replay enabled.</p>
<p>This is used for demand paging and page
migration. If XNACK replay is enabled in
the device, then if a page fault occurs
the code may execute incorrectly if the
<code class="docutils literal notranslate"><span class="pre">xnack</span></code> feature is not enabled. Executing
code that has the feature enabled on a
device that does not have XNACK replay
enabled will execute correctly, but may
be less performant than code with the
feature disabled.</p>
</td>
</tr>
<tr class="row-odd"><td><p>-m[no-]sram-ecc</p></td>
<td><p>Enable/disable generating code that assumes SRAM
ECC is enabled/disabled.</p></td>
</tr>
<tr class="row-even"><td><p>-m[no-]wavefrontsize64</p></td>
<td><p>Control the default wavefront size used when
generating code for kernels. When disabled
native wavefront size 32 is used, when enabled
wavefront size 64 is used.</p></td>
</tr>
<tr class="row-odd"><td><p>-m[no-]cumode</p></td>
<td><p>Control the default wavefront execution mode used
when generating code for kernels. When disabled
native WGP wavefront execution mode is used,
when enabled CU wavefront execution mode is used
(see <a class="reference internal" href="#amdgpu-amdhsa-memory-model"><span class="std std-ref">Memory Model</span></a>).</p></td>
</tr>
</tbody>
</table>
</dd>
</dl>
</div>
<div class="section" id="address-spaces">
<span id="amdgpu-address-spaces"></span><h3><a class="toc-backref" href="#id53">Address Spaces</a><a class="headerlink" href="#address-spaces" title="Permalink to this headline">¶</a></h3>
<p>The AMDGPU backend uses the following address space mappings.</p>
<p>The memory space names used in the table, aside from the region memory space, is
from the OpenCL standard.</p>
<p>LLVM Address Space number is used throughout LLVM (for example, in LLVM IR).</p>
<blockquote>
<div><table class="docutils align-default" id="amdgpu-address-space-mapping-table">
<caption><span class="caption-text">Address Space Mapping</span><a class="headerlink" href="#amdgpu-address-space-mapping-table" title="Permalink to this table">¶</a></caption>
<colgroup>
<col style="width: 35%" />
<col style="width: 65%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>LLVM Address Space</p></th>
<th class="head"><p>Memory Space</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>0</p></td>
<td><p>Generic (Flat)</p></td>
</tr>
<tr class="row-odd"><td><p>1</p></td>
<td><p>Global</p></td>
</tr>
<tr class="row-even"><td><p>2</p></td>
<td><p>Region (GDS)</p></td>
</tr>
<tr class="row-odd"><td><p>3</p></td>
<td><p>Local (group/LDS)</p></td>
</tr>
<tr class="row-even"><td><p>4</p></td>
<td><p>Constant</p></td>
</tr>
<tr class="row-odd"><td><p>5</p></td>
<td><p>Private (Scratch)</p></td>
</tr>
<tr class="row-even"><td><p>6</p></td>
<td><p>Constant 32-bit</p></td>
</tr>
<tr class="row-odd"><td><p>7</p></td>
<td><p>Buffer Fat Pointer (experimental)</p></td>
</tr>
</tbody>
</table>
</div></blockquote>
<p>The buffer fat pointer is an experimental address space that is currently
unsupported in the backend. It exposes a non-integral pointer that is in future
intended to support the modelling of 128-bit buffer descriptors + a 32-bit
offset into the buffer descriptor (in total encapsulating a 160-bit ‘pointer’),
allowing us to use normal LLVM load/store/atomic operations to model the buffer
descriptors used heavily in graphics workloads targeting the backend.</p>
</div>
<div class="section" id="memory-scopes">
<span id="amdgpu-memory-scopes"></span><h3><a class="toc-backref" href="#id54">Memory Scopes</a><a class="headerlink" href="#memory-scopes" title="Permalink to this headline">¶</a></h3>
<p>This section provides LLVM memory synchronization scopes supported by the AMDGPU
backend memory model when the target triple OS is <code class="docutils literal notranslate"><span class="pre">amdhsa</span></code> (see
<a class="reference internal" href="#amdgpu-amdhsa-memory-model"><span class="std std-ref">Memory Model</span></a> and <a class="reference internal" href="#amdgpu-target-triples"><span class="std std-ref">Target Triples</span></a>).</p>
<p>The memory model supported is based on the HSA memory model <a class="reference internal" href="#hsa" id="id12"><span>[HSA]</span></a> which is
based in turn on HRF-indirect with scope inclusion <a class="reference internal" href="#hrf" id="id13"><span>[HRF]</span></a>. The happens-before
relation is transitive over the synchonizes-with relation independent of scope,
and synchonizes-with allows the memory scope instances to be inclusive (see
table <a class="reference internal" href="#amdgpu-amdhsa-llvm-sync-scopes-table"><span class="std std-ref">AMDHSA LLVM Sync Scopes</span></a>).</p>
<p>This is different to the OpenCL <a class="reference internal" href="#id47" id="id14"><span>[OpenCL]</span></a> memory model which does not have scope
inclusion and requires the memory scopes to exactly match. However, this
is conservatively correct for OpenCL.</p>
<blockquote>
<div><table class="docutils align-default" id="amdgpu-amdhsa-llvm-sync-scopes-table">
<caption><span class="caption-text">AMDHSA LLVM Sync Scopes</span><a class="headerlink" href="#amdgpu-amdhsa-llvm-sync-scopes-table" title="Permalink to this table">¶</a></caption>
<colgroup>
<col style="width: 31%" />
<col style="width: 69%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>LLVM Sync Scope</p></th>
<th class="head"><p>Description</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p><em>none</em></p></td>
<td><p>The default: <code class="docutils literal notranslate"><span class="pre">system</span></code>.</p>
<p>Synchronizes with, and participates in modification
and seq_cst total orderings with, other operations
(except image operations) for all address spaces
(except private, or generic that accesses private)
provided the other operation’s sync scope is:</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">system</span></code>.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">agent</span></code> and executed by a thread on the same
agent.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">workgroup</span></code> and executed by a thread in the
same workgroup.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">wavefront</span></code> and executed by a thread in the
same wavefront.</p></li>
</ul>
</td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">agent</span></code></p></td>
<td><p>Synchronizes with, and participates in modification
and seq_cst total orderings with, other operations
(except image operations) for all address spaces
(except private, or generic that accesses private)
provided the other operation’s sync scope is:</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">system</span></code> or <code class="docutils literal notranslate"><span class="pre">agent</span></code> and executed by a thread
on the same agent.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">workgroup</span></code> and executed by a thread in the
same workgroup.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">wavefront</span></code> and executed by a thread in the
same wavefront.</p></li>
</ul>
</td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">workgroup</span></code></p></td>
<td><p>Synchronizes with, and participates in modification
and seq_cst total orderings with, other operations
(except image operations) for all address spaces
(except private, or generic that accesses private)
provided the other operation’s sync scope is:</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">system</span></code>, <code class="docutils literal notranslate"><span class="pre">agent</span></code> or <code class="docutils literal notranslate"><span class="pre">workgroup</span></code> and
executed by a thread in the same workgroup.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">wavefront</span></code> and executed by a thread in the
same wavefront.</p></li>
</ul>
</td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">wavefront</span></code></p></td>
<td><p>Synchronizes with, and participates in modification
and seq_cst total orderings with, other operations
(except image operations) for all address spaces
(except private, or generic that accesses private)
provided the other operation’s sync scope is:</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">system</span></code>, <code class="docutils literal notranslate"><span class="pre">agent</span></code>, <code class="docutils literal notranslate"><span class="pre">workgroup</span></code> or
<code class="docutils literal notranslate"><span class="pre">wavefront</span></code> and executed by a thread in the
same wavefront.</p></li>
</ul>
</td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">singlethread</span></code></p></td>
<td><p>Only synchronizes with, and participates in
modification and seq_cst total orderings with,
other operations (except image operations) running
in the same thread for all address spaces (for
example, in signal handlers).</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">one-as</span></code></p></td>
<td><p>Same as <code class="docutils literal notranslate"><span class="pre">system</span></code> but only synchronizes with other
operations within the same address space.</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">agent-one-as</span></code></p></td>
<td><p>Same as <code class="docutils literal notranslate"><span class="pre">agent</span></code> but only synchronizes with other
operations within the same address space.</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">workgroup-one-as</span></code></p></td>
<td><p>Same as <code class="docutils literal notranslate"><span class="pre">workgroup</span></code> but only synchronizes with
other operations within the same address space.</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">wavefront-one-as</span></code></p></td>
<td><p>Same as <code class="docutils literal notranslate"><span class="pre">wavefront</span></code> but only synchronizes with
other operations within the same address space.</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">singlethread-one-as</span></code></p></td>
<td><p>Same as <code class="docutils literal notranslate"><span class="pre">singlethread</span></code> but only synchronizes with
other operations within the same address space.</p></td>
</tr>
</tbody>
</table>
</div></blockquote>
</div>
<div class="section" id="amdgpu-intrinsics">
<h3><a class="toc-backref" href="#id55">AMDGPU Intrinsics</a><a class="headerlink" href="#amdgpu-intrinsics" title="Permalink to this headline">¶</a></h3>
<p>The AMDGPU backend implements the following LLVM IR intrinsics.</p>
<p><em>This section is WIP.</em></p>
</div>
<div class="section" id="amdgpu-attributes">
<h3><a class="toc-backref" href="#id56">AMDGPU Attributes</a><a class="headerlink" href="#amdgpu-attributes" title="Permalink to this headline">¶</a></h3>
<p>The AMDGPU backend supports the following LLVM IR attributes.</p>
<blockquote>
<div><table class="docutils align-default" id="amdgpu-llvm-ir-attributes-table">
<caption><span class="caption-text">AMDGPU LLVM IR Attributes</span><a class="headerlink" href="#amdgpu-llvm-ir-attributes-table" title="Permalink to this table">¶</a></caption>
<colgroup>
<col style="width: 36%" />
<col style="width: 64%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>LLVM Attribute</p></th>
<th class="head"><p>Description</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>“amdgpu-flat-work-group-size”=”min,max”</p></td>
<td><p>Specify the minimum and maximum flat work group sizes that
will be specified when the kernel is dispatched. Generated
by the <code class="docutils literal notranslate"><span class="pre">amdgpu_flat_work_group_size</span></code> CLANG attribute <a class="reference internal" href="#clang-attr" id="id15"><span>[CLANG-ATTR]</span></a>.</p></td>
</tr>
<tr class="row-odd"><td><p>“amdgpu-implicitarg-num-bytes”=”n”</p></td>
<td><p>Number of kernel argument bytes to add to the kernel
argument block size for the implicit arguments. This
varies by OS and language (for OpenCL see
<a class="reference internal" href="#opencl-kernel-implicit-arguments-appended-for-amdhsa-os-table"><span class="std std-ref">OpenCL kernel implicit arguments appended for AMDHSA OS</span></a>).</p></td>
</tr>
<tr class="row-even"><td><p>“amdgpu-num-sgpr”=”n”</p></td>
<td><p>Specifies the number of SGPRs to use. Generated by
the <code class="docutils literal notranslate"><span class="pre">amdgpu_num_sgpr</span></code> CLANG attribute <a class="reference internal" href="#clang-attr" id="id16"><span>[CLANG-ATTR]</span></a>.</p></td>
</tr>
<tr class="row-odd"><td><p>“amdgpu-num-vgpr”=”n”</p></td>
<td><p>Specifies the number of VGPRs to use. Generated by the
<code class="docutils literal notranslate"><span class="pre">amdgpu_num_vgpr</span></code> CLANG attribute <a class="reference internal" href="#clang-attr" id="id17"><span>[CLANG-ATTR]</span></a>.</p></td>
</tr>
<tr class="row-even"><td><p>“amdgpu-waves-per-eu”=”m,n”</p></td>
<td><p>Specify the minimum and maximum number of waves per
execution unit. Generated by the <code class="docutils literal notranslate"><span class="pre">amdgpu_waves_per_eu</span></code>
CLANG attribute <a class="reference internal" href="#clang-attr" id="id18"><span>[CLANG-ATTR]</span></a>.</p></td>
</tr>
<tr class="row-odd"><td><p>“amdgpu-ieee” true/false.</p></td>
<td><p>Specify whether the function expects the IEEE field of the
mode register to be set on entry. Overrides the default for
the calling convention.</p></td>
</tr>
<tr class="row-even"><td><p>“amdgpu-dx10-clamp” true/false.</p></td>
<td><p>Specify whether the function expects the DX10_CLAMP field of
the mode register to be set on entry. Overrides the default
for the calling convention.</p></td>
</tr>
</tbody>
</table>
</div></blockquote>
</div>
</div>
<div class="section" id="code-object">
<h2><a class="toc-backref" href="#id57">Code Object</a><a class="headerlink" href="#code-object" title="Permalink to this headline">¶</a></h2>
<p>The AMDGPU backend generates a standard ELF <a class="reference internal" href="#elf" id="id19"><span>[ELF]</span></a> relocatable code object that
can be linked by <code class="docutils literal notranslate"><span class="pre">lld</span></code> to produce a standard ELF shared code object which can
be loaded and executed on an AMDGPU target.</p>
<div class="section" id="header">
<h3><a class="toc-backref" href="#id58">Header</a><a class="headerlink" href="#header" title="Permalink to this headline">¶</a></h3>
<p>The AMDGPU backend uses the following ELF header:</p>
<blockquote>
<div><table class="docutils align-default" id="amdgpu-elf-header-table">
<caption><span class="caption-text">AMDGPU ELF Header</span><a class="headerlink" href="#amdgpu-elf-header-table" title="Permalink to this table">¶</a></caption>
<colgroup>
<col style="width: 38%" />
<col style="width: 62%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>Field</p></th>
<th class="head"><p>Value</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">e_ident[EI_CLASS]</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">ELFCLASS64</span></code></p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">e_ident[EI_DATA]</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">ELFDATA2LSB</span></code></p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">e_ident[EI_OSABI]</span></code></p></td>
<td><ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">ELFOSABI_NONE</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">ELFOSABI_AMDGPU_HSA</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">ELFOSABI_AMDGPU_PAL</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">ELFOSABI_AMDGPU_MESA3D</span></code></p></li>
</ul>
</td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">e_ident[EI_ABIVERSION]</span></code></p></td>
<td><ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">ELFABIVERSION_AMDGPU_HSA</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">ELFABIVERSION_AMDGPU_PAL</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">ELFABIVERSION_AMDGPU_MESA3D</span></code></p></li>
</ul>
</td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">e_type</span></code></p></td>
<td><ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">ET_REL</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">ET_DYN</span></code></p></li>
</ul>
</td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">e_machine</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">EM_AMDGPU</span></code></p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">e_entry</span></code></p></td>
<td><p>0</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">e_flags</span></code></p></td>
<td><p>See <a class="reference internal" href="#amdgpu-elf-header-e-flags-table"><span class="std std-ref">AMDGPU ELF Header e_flags</span></a></p></td>
</tr>
</tbody>
</table>
</div></blockquote>
<blockquote>
<div><table class="docutils align-default" id="amdgpu-elf-header-enumeration-values-table">
<caption><span class="caption-text">AMDGPU ELF Header Enumeration Values</span><a class="headerlink" href="#amdgpu-elf-header-enumeration-values-table" title="Permalink to this table">¶</a></caption>
<colgroup>
<col style="width: 86%" />
<col style="width: 14%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>Name</p></th>
<th class="head"><p>Value</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">EM_AMDGPU</span></code></p></td>
<td><p>224</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">ELFOSABI_NONE</span></code></p></td>
<td><p>0</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">ELFOSABI_AMDGPU_HSA</span></code></p></td>
<td><p>64</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">ELFOSABI_AMDGPU_PAL</span></code></p></td>
<td><p>65</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">ELFOSABI_AMDGPU_MESA3D</span></code></p></td>
<td><p>66</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">ELFABIVERSION_AMDGPU_HSA</span></code></p></td>
<td><p>1</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">ELFABIVERSION_AMDGPU_PAL</span></code></p></td>
<td><p>0</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">ELFABIVERSION_AMDGPU_MESA3D</span></code></p></td>
<td><p>0</p></td>
</tr>
</tbody>
</table>
</div></blockquote>
<dl>
<dt><code class="docutils literal notranslate"><span class="pre">e_ident[EI_CLASS]</span></code></dt><dd><p>The ELF class is:</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">ELFCLASS32</span></code> for <code class="docutils literal notranslate"><span class="pre">r600</span></code> architecture.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">ELFCLASS64</span></code> for <code class="docutils literal notranslate"><span class="pre">amdgcn</span></code> architecture which only supports 64
bit applications.</p></li>
</ul>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">e_ident[EI_DATA]</span></code></dt><dd><p>All AMDGPU targets use <code class="docutils literal notranslate"><span class="pre">ELFDATA2LSB</span></code> for little-endian byte ordering.</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">e_ident[EI_OSABI]</span></code></dt><dd><p>One of the following AMD GPU architecture specific OS ABIs
(see <a class="reference internal" href="#amdgpu-os-table"><span class="std std-ref">AMDGPU Operating Systems</span></a>):</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">ELFOSABI_NONE</span></code> for <em>unknown</em> OS.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">ELFOSABI_AMDGPU_HSA</span></code> for <code class="docutils literal notranslate"><span class="pre">amdhsa</span></code> OS.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">ELFOSABI_AMDGPU_PAL</span></code> for <code class="docutils literal notranslate"><span class="pre">amdpal</span></code> OS.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">ELFOSABI_AMDGPU_MESA3D</span></code> for <code class="docutils literal notranslate"><span class="pre">mesa3D</span></code> OS.</p></li>
</ul>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">e_ident[EI_ABIVERSION]</span></code></dt><dd><p>The ABI version of the AMD GPU architecture specific OS ABI to which the code
object conforms:</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">ELFABIVERSION_AMDGPU_HSA</span></code> is used to specify the version of AMD HSA
runtime ABI.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">ELFABIVERSION_AMDGPU_PAL</span></code> is used to specify the version of AMD PAL
runtime ABI.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">ELFABIVERSION_AMDGPU_MESA3D</span></code> is used to specify the version of AMD MESA
3D runtime ABI.</p></li>
</ul>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">e_type</span></code></dt><dd><p>Can be one of the following values:</p>
<dl class="simple">
<dt><code class="docutils literal notranslate"><span class="pre">ET_REL</span></code></dt><dd><p>The type produced by the AMD GPU backend compiler as it is relocatable code
object.</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">ET_DYN</span></code></dt><dd><p>The type produced by the linker as it is a shared code object.</p>
</dd>
</dl>
<p>The AMD HSA runtime loader requires a <code class="docutils literal notranslate"><span class="pre">ET_DYN</span></code> code object.</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">e_machine</span></code></dt><dd><p>The value <code class="docutils literal notranslate"><span class="pre">EM_AMDGPU</span></code> is used for the machine for all processors supported
by the <code class="docutils literal notranslate"><span class="pre">r600</span></code> and <code class="docutils literal notranslate"><span class="pre">amdgcn</span></code> architectures (see
<a class="reference internal" href="#amdgpu-processor-table"><span class="std std-ref">AMDGPU Processors</span></a>). The specific processor is specified in the
<code class="docutils literal notranslate"><span class="pre">EF_AMDGPU_MACH</span></code> bit field of the <code class="docutils literal notranslate"><span class="pre">e_flags</span></code> (see
<a class="reference internal" href="#amdgpu-elf-header-e-flags-table"><span class="std std-ref">AMDGPU ELF Header e_flags</span></a>).</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">e_entry</span></code></dt><dd><p>The entry point is 0 as the entry points for individual kernels must be
selected in order to invoke them through AQL packets.</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">e_flags</span></code></dt><dd><p>The AMDGPU backend uses the following ELF header flags:</p>
<table class="docutils align-default" id="amdgpu-elf-header-e-flags-table">
<caption><span class="caption-text">AMDGPU ELF Header <code class="docutils literal notranslate"><span class="pre">e_flags</span></code></span><a class="headerlink" href="#amdgpu-elf-header-e-flags-table" title="Permalink to this table">¶</a></caption>
<colgroup>
<col style="width: 42%" />
<col style="width: 13%" />
<col style="width: 45%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>Name</p></th>
<th class="head"><p>Value</p></th>
<th class="head"><p>Description</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td colspan="2"><p><strong>AMDGPU Processor Flag</strong></p></td>
<td><p>See <a class="reference internal" href="#amdgpu-processor-table"><span class="std std-ref">AMDGPU Processors</span></a>.</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">EF_AMDGPU_MACH</span></code></p></td>
<td><p>0x000000ff</p></td>
<td><p>AMDGPU processor selection
mask for
<code class="docutils literal notranslate"><span class="pre">EF_AMDGPU_MACH_xxx</span></code> values
defined in
<a class="reference internal" href="#amdgpu-ef-amdgpu-mach-table"><span class="std std-ref">AMDGPU EF_AMDGPU_MACH Values</span></a>.</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">EF_AMDGPU_XNACK</span></code></p></td>
<td><p>0x00000100</p></td>
<td><p>Indicates if the <code class="docutils literal notranslate"><span class="pre">xnack</span></code>
target feature is
enabled for all code
contained in the code object.
If the processor
does not support the
<code class="docutils literal notranslate"><span class="pre">xnack</span></code> target
feature then must
be 0.
See
<a class="reference internal" href="#amdgpu-target-features"><span class="std std-ref">Target Features</span></a>.</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">EF_AMDGPU_SRAM_ECC</span></code></p></td>
<td><p>0x00000200</p></td>
<td><p>Indicates if the <code class="docutils literal notranslate"><span class="pre">sram-ecc</span></code>
target feature is
enabled for all code
contained in the code object.
If the processor
does not support the
<code class="docutils literal notranslate"><span class="pre">sram-ecc</span></code> target
feature then must
be 0.
See
<a class="reference internal" href="#amdgpu-target-features"><span class="std std-ref">Target Features</span></a>.</p></td>
</tr>
</tbody>
</table>
<table class="docutils align-default" id="amdgpu-ef-amdgpu-mach-table">
<caption><span class="caption-text">AMDGPU <code class="docutils literal notranslate"><span class="pre">EF_AMDGPU_MACH</span></code> Values</span><a class="headerlink" href="#amdgpu-ef-amdgpu-mach-table" title="Permalink to this table">¶</a></caption>
<colgroup>
<col style="width: 45%" />
<col style="width: 14%" />
<col style="width: 41%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>Name</p></th>
<th class="head"><p>Value</p></th>
<th class="head"><p>Description (see
<a class="reference internal" href="#amdgpu-processor-table"><span class="std std-ref">AMDGPU Processors</span></a>)</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">EF_AMDGPU_MACH_NONE</span></code></p></td>
<td><p>0x000</p></td>
<td><p><em>not specified</em></p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">EF_AMDGPU_MACH_R600_R600</span></code></p></td>
<td><p>0x001</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">r600</span></code></p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">EF_AMDGPU_MACH_R600_R630</span></code></p></td>
<td><p>0x002</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">r630</span></code></p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">EF_AMDGPU_MACH_R600_RS880</span></code></p></td>
<td><p>0x003</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">rs880</span></code></p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">EF_AMDGPU_MACH_R600_RV670</span></code></p></td>
<td><p>0x004</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">rv670</span></code></p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">EF_AMDGPU_MACH_R600_RV710</span></code></p></td>
<td><p>0x005</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">rv710</span></code></p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">EF_AMDGPU_MACH_R600_RV730</span></code></p></td>
<td><p>0x006</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">rv730</span></code></p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">EF_AMDGPU_MACH_R600_RV770</span></code></p></td>
<td><p>0x007</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">rv770</span></code></p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">EF_AMDGPU_MACH_R600_CEDAR</span></code></p></td>
<td><p>0x008</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">cedar</span></code></p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">EF_AMDGPU_MACH_R600_CYPRESS</span></code></p></td>
<td><p>0x009</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">cypress</span></code></p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">EF_AMDGPU_MACH_R600_JUNIPER</span></code></p></td>
<td><p>0x00a</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">juniper</span></code></p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">EF_AMDGPU_MACH_R600_REDWOOD</span></code></p></td>
<td><p>0x00b</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">redwood</span></code></p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">EF_AMDGPU_MACH_R600_SUMO</span></code></p></td>
<td><p>0x00c</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">sumo</span></code></p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">EF_AMDGPU_MACH_R600_BARTS</span></code></p></td>
<td><p>0x00d</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">barts</span></code></p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">EF_AMDGPU_MACH_R600_CAICOS</span></code></p></td>
<td><p>0x00e</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">caicos</span></code></p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">EF_AMDGPU_MACH_R600_CAYMAN</span></code></p></td>
<td><p>0x00f</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">cayman</span></code></p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">EF_AMDGPU_MACH_R600_TURKS</span></code></p></td>
<td><p>0x010</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">turks</span></code></p></td>
</tr>
<tr class="row-odd"><td><p><em>reserved</em></p></td>
<td><p>0x011 -
0x01f</p></td>
<td><p>Reserved for <code class="docutils literal notranslate"><span class="pre">r600</span></code>
architecture processors.</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">EF_AMDGPU_MACH_AMDGCN_GFX600</span></code></p></td>
<td><p>0x020</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">gfx600</span></code></p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">EF_AMDGPU_MACH_AMDGCN_GFX601</span></code></p></td>
<td><p>0x021</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">gfx601</span></code></p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">EF_AMDGPU_MACH_AMDGCN_GFX700</span></code></p></td>
<td><p>0x022</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">gfx700</span></code></p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">EF_AMDGPU_MACH_AMDGCN_GFX701</span></code></p></td>
<td><p>0x023</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">gfx701</span></code></p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">EF_AMDGPU_MACH_AMDGCN_GFX702</span></code></p></td>
<td><p>0x024</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">gfx702</span></code></p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">EF_AMDGPU_MACH_AMDGCN_GFX703</span></code></p></td>
<td><p>0x025</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">gfx703</span></code></p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">EF_AMDGPU_MACH_AMDGCN_GFX704</span></code></p></td>
<td><p>0x026</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">gfx704</span></code></p></td>
</tr>
<tr class="row-odd"><td><p><em>reserved</em></p></td>
<td><p>0x027</p></td>
<td><p>Reserved.</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">EF_AMDGPU_MACH_AMDGCN_GFX801</span></code></p></td>
<td><p>0x028</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">gfx801</span></code></p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">EF_AMDGPU_MACH_AMDGCN_GFX802</span></code></p></td>
<td><p>0x029</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">gfx802</span></code></p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">EF_AMDGPU_MACH_AMDGCN_GFX803</span></code></p></td>
<td><p>0x02a</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">gfx803</span></code></p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">EF_AMDGPU_MACH_AMDGCN_GFX810</span></code></p></td>
<td><p>0x02b</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">gfx810</span></code></p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">EF_AMDGPU_MACH_AMDGCN_GFX900</span></code></p></td>
<td><p>0x02c</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">gfx900</span></code></p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">EF_AMDGPU_MACH_AMDGCN_GFX902</span></code></p></td>
<td><p>0x02d</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">gfx902</span></code></p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">EF_AMDGPU_MACH_AMDGCN_GFX904</span></code></p></td>
<td><p>0x02e</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">gfx904</span></code></p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">EF_AMDGPU_MACH_AMDGCN_GFX906</span></code></p></td>
<td><p>0x02f</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">gfx906</span></code></p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">EF_AMDGPU_MACH_AMDGCN_GFX908</span></code></p></td>
<td><p>0x030</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">gfx908</span></code></p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">EF_AMDGPU_MACH_AMDGCN_GFX909</span></code></p></td>
<td><p>0x031</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">gfx909</span></code></p></td>
</tr>
<tr class="row-even"><td><p><em>reserved</em></p></td>
<td><p>0x032</p></td>
<td><p>Reserved.</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">EF_AMDGPU_MACH_AMDGCN_GFX1010</span></code></p></td>
<td><p>0x033</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">gfx1010</span></code></p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">EF_AMDGPU_MACH_AMDGCN_GFX1011</span></code></p></td>
<td><p>0x034</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">gfx1011</span></code></p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">EF_AMDGPU_MACH_AMDGCN_GFX1012</span></code></p></td>
<td><p>0x035</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">gfx1012</span></code></p></td>
</tr>
</tbody>
</table>
</dd>
</dl>
</div>
<div class="section" id="sections">
<h3><a class="toc-backref" href="#id59">Sections</a><a class="headerlink" href="#sections" title="Permalink to this headline">¶</a></h3>
<p>An AMDGPU target ELF code object has the standard ELF sections which include:</p>
<blockquote>
<div><table class="docutils align-default" id="amdgpu-elf-sections-table">
<caption><span class="caption-text">AMDGPU ELF Sections</span><a class="headerlink" href="#amdgpu-elf-sections-table" title="Permalink to this table">¶</a></caption>
<colgroup>
<col style="width: 27%" />
<col style="width: 24%" />
<col style="width: 49%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>Name</p></th>
<th class="head"><p>Type</p></th>
<th class="head"><p>Attributes</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">.bss</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">SHT_NOBITS</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">SHF_ALLOC</span></code> + <code class="docutils literal notranslate"><span class="pre">SHF_WRITE</span></code></p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">.data</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">SHT_PROGBITS</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">SHF_ALLOC</span></code> + <code class="docutils literal notranslate"><span class="pre">SHF_WRITE</span></code></p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">.debug_</span></code><em>*</em></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">SHT_PROGBITS</span></code></p></td>
<td><p><em>none</em></p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">.dynamic</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">SHT_DYNAMIC</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">SHF_ALLOC</span></code></p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">.dynstr</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">SHT_PROGBITS</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">SHF_ALLOC</span></code></p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">.dynsym</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">SHT_PROGBITS</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">SHF_ALLOC</span></code></p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">.got</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">SHT_PROGBITS</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">SHF_ALLOC</span></code> + <code class="docutils literal notranslate"><span class="pre">SHF_WRITE</span></code></p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">.hash</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">SHT_HASH</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">SHF_ALLOC</span></code></p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">.note</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">SHT_NOTE</span></code></p></td>
<td><p><em>none</em></p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">.rela</span></code><em>name</em></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">SHT_RELA</span></code></p></td>
<td><p><em>none</em></p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">.rela.dyn</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">SHT_RELA</span></code></p></td>
<td><p><em>none</em></p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">.rodata</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">SHT_PROGBITS</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">SHF_ALLOC</span></code></p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">.shstrtab</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">SHT_STRTAB</span></code></p></td>
<td><p><em>none</em></p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">.strtab</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">SHT_STRTAB</span></code></p></td>
<td><p><em>none</em></p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">.symtab</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">SHT_SYMTAB</span></code></p></td>
<td><p><em>none</em></p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">.text</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">SHT_PROGBITS</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">SHF_ALLOC</span></code> + <code class="docutils literal notranslate"><span class="pre">SHF_EXECINSTR</span></code></p></td>
</tr>
</tbody>
</table>
</div></blockquote>
<p>These sections have their standard meanings (see <a class="reference internal" href="#elf" id="id20"><span>[ELF]</span></a>) and are only generated
if needed.</p>
<dl>
<dt><code class="docutils literal notranslate"><span class="pre">.debug</span></code><em>*</em></dt><dd><p>The standard DWARF sections. See <a class="reference internal" href="#amdgpu-dwarf"><span class="std std-ref">DWARF</span></a> for information on the
DWARF produced by the AMDGPU backend.</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">.dynamic</span></code>, <code class="docutils literal notranslate"><span class="pre">.dynstr</span></code>, <code class="docutils literal notranslate"><span class="pre">.dynsym</span></code>, <code class="docutils literal notranslate"><span class="pre">.hash</span></code></dt><dd><p>The standard sections used by a dynamic loader.</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">.note</span></code></dt><dd><p>See <a class="reference internal" href="#amdgpu-note-records"><span class="std std-ref">Note Records</span></a> for the note records supported by the AMDGPU
backend.</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">.rela</span></code><em>name</em>, <code class="docutils literal notranslate"><span class="pre">.rela.dyn</span></code></dt><dd><p>For relocatable code objects, <em>name</em> is the name of the section that the
relocation records apply. For example, <code class="docutils literal notranslate"><span class="pre">.rela.text</span></code> is the section name for
relocation records associated with the <code class="docutils literal notranslate"><span class="pre">.text</span></code> section.</p>
<p>For linked shared code objects, <code class="docutils literal notranslate"><span class="pre">.rela.dyn</span></code> contains all the relocation
records from each of the relocatable code object’s <code class="docutils literal notranslate"><span class="pre">.rela</span></code><em>name</em> sections.</p>
<p>See <a class="reference internal" href="#amdgpu-relocation-records"><span class="std std-ref">Relocation Records</span></a> for the relocation records supported by
the AMDGPU backend.</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">.text</span></code></dt><dd><p>The executable machine code for the kernels and functions they call. Generated
as position independent code. See <a class="reference internal" href="#amdgpu-code-conventions"><span class="std std-ref">Code Conventions</span></a> for
information on conventions used in the isa generation.</p>
</dd>
</dl>
</div>
<div class="section" id="note-records">
<span id="amdgpu-note-records"></span><h3><a class="toc-backref" href="#id60">Note Records</a><a class="headerlink" href="#note-records" title="Permalink to this headline">¶</a></h3>
<p>The AMDGPU backend code object contains ELF note records in the <code class="docutils literal notranslate"><span class="pre">.note</span></code>
section. The set of generated notes and their semantics depend on the code
object version; see <a class="reference internal" href="#amdgpu-note-records-v2"><span class="std std-ref">Code Object V2 Note Records (-mattr=-code-object-v3)</span></a> and
<a class="reference internal" href="#amdgpu-note-records-v3"><span class="std std-ref">Code Object V3 Note Records (-mattr=+code-object-v3)</span></a>.</p>
<p>As required by <code class="docutils literal notranslate"><span class="pre">ELFCLASS32</span></code> and <code class="docutils literal notranslate"><span class="pre">ELFCLASS64</span></code>, minimal zero byte padding
must be generated after the <code class="docutils literal notranslate"><span class="pre">name</span></code> field to ensure the <code class="docutils literal notranslate"><span class="pre">desc</span></code> field is 4
byte aligned. In addition, minimal zero byte padding must be generated to
ensure the <code class="docutils literal notranslate"><span class="pre">desc</span></code> field size is a multiple of 4 bytes. The <code class="docutils literal notranslate"><span class="pre">sh_addralign</span></code>
field of the <code class="docutils literal notranslate"><span class="pre">.note</span></code> section must be at least 4 to indicate at least 8 byte
alignment.</p>
<div class="section" id="code-object-v2-note-records-mattr-code-object-v3">
<span id="amdgpu-note-records-v2"></span><h4><a class="toc-backref" href="#id61">Code Object V2 Note Records (-mattr=-code-object-v3)</a><a class="headerlink" href="#code-object-v2-note-records-mattr-code-object-v3" title="Permalink to this headline">¶</a></h4>
<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p>Code Object V2 is not the default code object version emitted by
this version of LLVM. For a description of the notes generated with the
default configuration (Code Object V3) see <a class="reference internal" href="#amdgpu-note-records-v3"><span class="std std-ref">Code Object V3 Note Records (-mattr=+code-object-v3)</span></a>.</p>
</div>
<p>The AMDGPU backend code object uses the following ELF note record in the
<code class="docutils literal notranslate"><span class="pre">.note</span></code> section when compiling for Code Object V2 (-mattr=-code-object-v3).</p>
<p>Additional note records may be present, but any which are not documented here
are deprecated and should not be used.</p>
<blockquote>
<div><table class="docutils align-default" id="amdgpu-elf-note-records-table-v2">
<caption><span class="caption-text">AMDGPU Code Object V2 ELF Note Records</span><a class="headerlink" href="#amdgpu-elf-note-records-table-v2" title="Permalink to this table">¶</a></caption>
<colgroup>
<col style="width: 7%" />
<col style="width: 41%" />
<col style="width: 52%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>Name</p></th>
<th class="head"><p>Type</p></th>
<th class="head"><p>Description</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>“AMD”</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">NT_AMD_AMDGPU_HSA_METADATA</span></code></p></td>
<td><p>&lt;metadata null terminated string&gt;</p></td>
</tr>
</tbody>
</table>
</div></blockquote>
<blockquote>
<div><table class="docutils align-default" id="amdgpu-elf-note-record-enumeration-values-table-v2">
<caption><span class="caption-text">AMDGPU Code Object V2 ELF Note Record Enumeration Values</span><a class="headerlink" href="#amdgpu-elf-note-record-enumeration-values-table-v2" title="Permalink to this table">¶</a></caption>
<colgroup>
<col style="width: 86%" />
<col style="width: 14%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>Name</p></th>
<th class="head"><p>Value</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p><em>reserved</em></p></td>
<td><p>0-9</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">NT_AMD_AMDGPU_HSA_METADATA</span></code></p></td>
<td><p>10</p></td>
</tr>
<tr class="row-even"><td><p><em>reserved</em></p></td>
<td><p>11</p></td>
</tr>
</tbody>
</table>
</div></blockquote>
<dl class="simple">
<dt><code class="docutils literal notranslate"><span class="pre">NT_AMD_AMDGPU_HSA_METADATA</span></code></dt><dd><p>Specifies extensible metadata associated with the code objects executed on HSA
<a class="reference internal" href="#hsa" id="id21"><span>[HSA]</span></a> compatible runtimes such as AMD’s ROCm <a class="reference internal" href="#amd-rocm" id="id22"><span>[AMD-ROCm]</span></a>. It is required when
the target triple OS is <code class="docutils literal notranslate"><span class="pre">amdhsa</span></code> (see <a class="reference internal" href="#amdgpu-target-triples"><span class="std std-ref">Target Triples</span></a>). See
<a class="reference internal" href="#amdgpu-amdhsa-code-object-metadata-v2"><span class="std std-ref">Code Object V2 Metadata (-mattr=-code-object-v3)</span></a> for the syntax of the code
object metadata string.</p>
</dd>
</dl>
</div>
<div class="section" id="code-object-v3-note-records-mattr-code-object-v3">
<span id="amdgpu-note-records-v3"></span><h4><a class="toc-backref" href="#id62">Code Object V3 Note Records (-mattr=+code-object-v3)</a><a class="headerlink" href="#code-object-v3-note-records-mattr-code-object-v3" title="Permalink to this headline">¶</a></h4>
<p>The AMDGPU backend code object uses the following ELF note record in the
<code class="docutils literal notranslate"><span class="pre">.note</span></code> section when compiling for Code Object V3 (-mattr=+code-object-v3).</p>
<p>Additional note records may be present, but any which are not documented here
are deprecated and should not be used.</p>
<blockquote>
<div><table class="docutils align-default" id="amdgpu-elf-note-records-table-v3">
<caption><span class="caption-text">AMDGPU Code Object V3 ELF Note Records</span><a class="headerlink" href="#amdgpu-elf-note-records-table-v3" title="Permalink to this table">¶</a></caption>
<colgroup>
<col style="width: 11%" />
<col style="width: 39%" />
<col style="width: 50%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>Name</p></th>
<th class="head"><p>Type</p></th>
<th class="head"><p>Description</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>“AMDGPU”</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">NT_AMDGPU_METADATA</span></code></p></td>
<td><p>Metadata in Message Pack <a class="reference internal" href="#msgpack" id="id23"><span>[MsgPack]</span></a>
binary format.</p></td>
</tr>
</tbody>
</table>
</div></blockquote>
<blockquote>
<div><table class="docutils align-default" id="amdgpu-elf-note-record-enumeration-values-table-v3">
<caption><span class="caption-text">AMDGPU Code Object V3 ELF Note Record Enumeration Values</span><a class="headerlink" href="#amdgpu-elf-note-record-enumeration-values-table-v3" title="Permalink to this table">¶</a></caption>
<colgroup>
<col style="width: 86%" />
<col style="width: 14%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>Name</p></th>
<th class="head"><p>Value</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p><em>reserved</em></p></td>
<td><p>0-31</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">NT_AMDGPU_METADATA</span></code></p></td>
<td><p>32</p></td>
</tr>
</tbody>
</table>
</div></blockquote>
<dl class="simple">
<dt><code class="docutils literal notranslate"><span class="pre">NT_AMDGPU_METADATA</span></code></dt><dd><p>Specifies extensible metadata associated with an AMDGPU code
object. It is encoded as a map in the Message Pack <a class="reference internal" href="#msgpack" id="id24"><span>[MsgPack]</span></a> binary
data format. See <a class="reference internal" href="#amdgpu-amdhsa-code-object-metadata-v3"><span class="std std-ref">Code Object V3 Metadata (-mattr=+code-object-v3)</span></a> for the
map keys defined for the <code class="docutils literal notranslate"><span class="pre">amdhsa</span></code> OS.</p>
</dd>
</dl>
</div>
</div>
<div class="section" id="symbols">
<span id="amdgpu-symbols"></span><h3><a class="toc-backref" href="#id63">Symbols</a><a class="headerlink" href="#symbols" title="Permalink to this headline">¶</a></h3>
<p>Symbols include the following:</p>
<blockquote>
<div><table class="docutils align-default" id="amdgpu-elf-symbols-table">
<caption><span class="caption-text">AMDGPU ELF Symbols</span><a class="headerlink" href="#amdgpu-elf-symbols-table" title="Permalink to this table">¶</a></caption>
<colgroup>
<col style="width: 27%" />
<col style="width: 23%" />
<col style="width: 21%" />
<col style="width: 29%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>Name</p></th>
<th class="head"><p>Type</p></th>
<th class="head"><p>Section</p></th>
<th class="head"><p>Description</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p><em>link-name</em></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">STT_OBJECT</span></code></p></td>
<td><ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">.data</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">.rodata</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">.bss</span></code></p></li>
</ul>
</td>
<td><p>Global variable</p></td>
</tr>
<tr class="row-odd"><td><p><em>link-name</em><code class="docutils literal notranslate"><span class="pre">.kd</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">STT_OBJECT</span></code></p></td>
<td><ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">.rodata</span></code></p></li>
</ul>
</td>
<td><p>Kernel descriptor</p></td>
</tr>
<tr class="row-even"><td><p><em>link-name</em></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">STT_FUNC</span></code></p></td>
<td><ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">.text</span></code></p></li>
</ul>
</td>
<td><p>Kernel entry point</p></td>
</tr>
<tr class="row-odd"><td><p><em>link-name</em></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">STT_OBJECT</span></code></p></td>
<td><ul class="simple">
<li><p>SHN_AMDGPU_LDS</p></li>
</ul>
</td>
<td><p>Global variable in LDS</p></td>
</tr>
</tbody>
</table>
</div></blockquote>
<dl>
<dt>Global variable</dt><dd><p>Global variables both used and defined by the compilation unit.</p>
<p>If the symbol is defined in the compilation unit then it is allocated in the
appropriate section according to if it has initialized data or is readonly.</p>
<p>If the symbol is external then its section is <code class="docutils literal notranslate"><span class="pre">STN_UNDEF</span></code> and the loader
will resolve relocations using the definition provided by another code object
or explicitly defined by the runtime.</p>
<p>If the symbol resides in local/group memory (LDS) then its section is the
special processor-specific section name <code class="docutils literal notranslate"><span class="pre">SHN_AMDGPU_LDS</span></code>, and the
<code class="docutils literal notranslate"><span class="pre">st_value</span></code> field describes alignment requirements as it does for common
symbols.</p>
</dd>
<dt>Kernel descriptor</dt><dd><p>Every HSA kernel has an associated kernel descriptor. It is the address of the
kernel descriptor that is used in the AQL dispatch packet used to invoke the
kernel, not the kernel entry point. The layout of the HSA kernel descriptor is
defined in <a class="reference internal" href="#amdgpu-amdhsa-kernel-descriptor"><span class="std std-ref">Kernel Descriptor</span></a>.</p>
</dd>
<dt>Kernel entry point</dt><dd><p>Every HSA kernel also has a symbol for its machine code entry point.</p>
</dd>
</dl>
</div>
<div class="section" id="relocation-records">
<span id="amdgpu-relocation-records"></span><h3><a class="toc-backref" href="#id64">Relocation Records</a><a class="headerlink" href="#relocation-records" title="Permalink to this headline">¶</a></h3>
<p>AMDGPU backend generates <code class="docutils literal notranslate"><span class="pre">Elf64_Rela</span></code> relocation records. Supported
relocatable fields are:</p>
<dl class="simple">
<dt><code class="docutils literal notranslate"><span class="pre">word32</span></code></dt><dd><p>This specifies a 32-bit field occupying 4 bytes with arbitrary byte
alignment. These values use the same byte order as other word values in the
AMD GPU architecture.</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">word64</span></code></dt><dd><p>This specifies a 64-bit field occupying 8 bytes with arbitrary byte
alignment. These values use the same byte order as other word values in the
AMD GPU architecture.</p>
</dd>
</dl>
<p>Following notations are used for specifying relocation calculations:</p>
<dl class="simple">
<dt><strong>A</strong></dt><dd><p>Represents the addend used to compute the value of the relocatable field.</p>
</dd>
<dt><strong>G</strong></dt><dd><p>Represents the offset into the global offset table at which the relocation
entry’s symbol will reside during execution.</p>
</dd>
<dt><strong>GOT</strong></dt><dd><p>Represents the address of the global offset table.</p>
</dd>
<dt><strong>P</strong></dt><dd><p>Represents the place (section offset for <code class="docutils literal notranslate"><span class="pre">et_rel</span></code> or address for <code class="docutils literal notranslate"><span class="pre">et_dyn</span></code>)
of the storage unit being relocated (computed using <code class="docutils literal notranslate"><span class="pre">r_offset</span></code>).</p>
</dd>
<dt><strong>S</strong></dt><dd><p>Represents the value of the symbol whose index resides in the relocation
entry. Relocations not using this must specify a symbol index of <code class="docutils literal notranslate"><span class="pre">STN_UNDEF</span></code>.</p>
</dd>
<dt><strong>B</strong></dt><dd><p>Represents the base address of a loaded executable or shared object which is
the difference between the ELF address and the actual load address. Relocations
using this are only valid in executable or shared objects.</p>
</dd>
</dl>
<p>The following relocation types are supported:</p>
<blockquote>
<div><table class="docutils align-default" id="amdgpu-elf-relocation-records-table">
<caption><span class="caption-text">AMDGPU ELF Relocation Records</span><a class="headerlink" href="#amdgpu-elf-relocation-records-table" title="Permalink to this table">¶</a></caption>
<colgroup>
<col style="width: 33%" />
<col style="width: 9%" />
<col style="width: 6%" />
<col style="width: 13%" />
<col style="width: 38%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>Relocation Type</p></th>
<th class="head"><p>Kind</p></th>
<th class="head"><p>Value</p></th>
<th class="head"><p>Field</p></th>
<th class="head"><p>Calculation</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">R_AMDGPU_NONE</span></code></p></td>
<td></td>
<td><p>0</p></td>
<td><p><em>none</em></p></td>
<td><p><em>none</em></p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">R_AMDGPU_ABS32_LO</span></code></p></td>
<td><p>Static,
Dynamic</p></td>
<td><p>1</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">word32</span></code></p></td>
<td><p>(S + A) &amp; 0xFFFFFFFF</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">R_AMDGPU_ABS32_HI</span></code></p></td>
<td><p>Static,
Dynamic</p></td>
<td><p>2</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">word32</span></code></p></td>
<td><p>(S + A) &gt;&gt; 32</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">R_AMDGPU_ABS64</span></code></p></td>
<td><p>Static,
Dynamic</p></td>
<td><p>3</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">word64</span></code></p></td>
<td><p>S + A</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">R_AMDGPU_REL32</span></code></p></td>
<td><p>Static</p></td>
<td><p>4</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">word32</span></code></p></td>
<td><p>S + A - P</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">R_AMDGPU_REL64</span></code></p></td>
<td><p>Static</p></td>
<td><p>5</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">word64</span></code></p></td>
<td><p>S + A - P</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">R_AMDGPU_ABS32</span></code></p></td>
<td><p>Static,
Dynamic</p></td>
<td><p>6</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">word32</span></code></p></td>
<td><p>S + A</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">R_AMDGPU_GOTPCREL</span></code></p></td>
<td><p>Static</p></td>
<td><p>7</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">word32</span></code></p></td>
<td><p>G + GOT + A - P</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">R_AMDGPU_GOTPCREL32_LO</span></code></p></td>
<td><p>Static</p></td>
<td><p>8</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">word32</span></code></p></td>
<td><p>(G + GOT + A - P) &amp; 0xFFFFFFFF</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">R_AMDGPU_GOTPCREL32_HI</span></code></p></td>
<td><p>Static</p></td>
<td><p>9</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">word32</span></code></p></td>
<td><p>(G + GOT + A - P) &gt;&gt; 32</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">R_AMDGPU_REL32_LO</span></code></p></td>
<td><p>Static</p></td>
<td><p>10</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">word32</span></code></p></td>
<td><p>(S + A - P) &amp; 0xFFFFFFFF</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">R_AMDGPU_REL32_HI</span></code></p></td>
<td><p>Static</p></td>
<td><p>11</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">word32</span></code></p></td>
<td><p>(S + A - P) &gt;&gt; 32</p></td>
</tr>
<tr class="row-even"><td><p><em>reserved</em></p></td>
<td></td>
<td><p>12</p></td>
<td></td>
<td></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">R_AMDGPU_RELATIVE64</span></code></p></td>
<td><p>Dynamic</p></td>
<td><p>13</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">word64</span></code></p></td>
<td><p>B + A</p></td>
</tr>
</tbody>
</table>
</div></blockquote>
<p><code class="docutils literal notranslate"><span class="pre">R_AMDGPU_ABS32_LO</span></code> and <code class="docutils literal notranslate"><span class="pre">R_AMDGPU_ABS32_HI</span></code> are only supported by
the <code class="docutils literal notranslate"><span class="pre">mesa3d</span></code> OS, which does not support <code class="docutils literal notranslate"><span class="pre">R_AMDGPU_ABS64</span></code>.</p>
<p>There is no current OS loader support for 32 bit programs and so
<code class="docutils literal notranslate"><span class="pre">R_AMDGPU_ABS32</span></code> is not used.</p>
</div>
<div class="section" id="dwarf">
<span id="amdgpu-dwarf"></span><h3><a class="toc-backref" href="#id65">DWARF</a><a class="headerlink" href="#dwarf" title="Permalink to this headline">¶</a></h3>
<p>Standard DWARF <a class="reference internal" href="#id46" id="id25"><span>[DWARF]</span></a> Version 5 sections can be generated. These contain
information that maps the code object executable code and data to the source
language constructs. It can be used by tools such as debuggers and profilers.</p>
<div class="section" id="address-space-mapping">
<h4><a class="toc-backref" href="#id66">Address Space Mapping</a><a class="headerlink" href="#address-space-mapping" title="Permalink to this headline">¶</a></h4>
<p>The following address space mapping is used:</p>
<blockquote>
<div><table class="docutils align-default" id="amdgpu-dwarf-address-space-mapping-table">
<caption><span class="caption-text">AMDGPU DWARF Address Space Mapping</span><a class="headerlink" href="#amdgpu-dwarf-address-space-mapping-table" title="Permalink to this table">¶</a></caption>
<colgroup>
<col style="width: 53%" />
<col style="width: 47%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>DWARF Address Space</p></th>
<th class="head"><p>Memory Space</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>1</p></td>
<td><p>Private (Scratch)</p></td>
</tr>
<tr class="row-odd"><td><p>2</p></td>
<td><p>Local (group/LDS)</p></td>
</tr>
<tr class="row-even"><td><p><em>omitted</em></p></td>
<td><p>Global</p></td>
</tr>
<tr class="row-odd"><td><p><em>omitted</em></p></td>
<td><p>Constant</p></td>
</tr>
<tr class="row-even"><td><p><em>omitted</em></p></td>
<td><p>Generic (Flat)</p></td>
</tr>
<tr class="row-odd"><td><p><em>not supported</em></p></td>
<td><p>Region (GDS)</p></td>
</tr>
</tbody>
</table>
</div></blockquote>
<p>See <a class="reference internal" href="#amdgpu-address-spaces"><span class="std std-ref">Address Spaces</span></a> for information on the memory space terminology
used in the table.</p>
<p>An <code class="docutils literal notranslate"><span class="pre">address_class</span></code> attribute is generated on pointer type DIEs to specify the
DWARF address space of the value of the pointer when it is in the <em>private</em> or
<em>local</em> address space. Otherwise the attribute is omitted.</p>
<p>An <code class="docutils literal notranslate"><span class="pre">XDEREF</span></code> operation is generated in location list expressions for variables
that are allocated in the <em>private</em> and <em>local</em> address space. Otherwise no
<code class="docutils literal notranslate"><span class="pre">XDREF</span></code> is omitted.</p>
</div>
<div class="section" id="register-mapping">
<h4><a class="toc-backref" href="#id67">Register Mapping</a><a class="headerlink" href="#register-mapping" title="Permalink to this headline">¶</a></h4>
<p><em>This section is WIP.</em></p>
</div>
<div class="section" id="source-text">
<h4><a class="toc-backref" href="#id68">Source Text</a><a class="headerlink" href="#source-text" title="Permalink to this headline">¶</a></h4>
<p>Source text for online-compiled programs (e.g. those compiled by the OpenCL
runtime) may be embedded into the DWARF v5 line table using the <code class="docutils literal notranslate"><span class="pre">clang</span>
<span class="pre">-gembed-source</span></code> option, described in table <a class="reference internal" href="#amdgpu-debug-options"><span class="std std-ref">AMDGPU Debug Options</span></a>.</p>
<p>For example:</p>
<dl>
<dt><code class="docutils literal notranslate"><span class="pre">-gembed-source</span></code></dt><dd><p>Enable the embedded source DWARF v5 extension.</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">-gno-embed-source</span></code></dt><dd><p>Disable the embedded source DWARF v5 extension.</p>
<table class="docutils align-default" id="amdgpu-debug-options">
<caption><span class="caption-text">AMDGPU Debug Options</span><a class="headerlink" href="#amdgpu-debug-options" title="Permalink to this table">¶</a></caption>
<colgroup>
<col style="width: 29%" />
<col style="width: 71%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>Debug Flag</p></th>
<th class="head"><p>Description</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>-g[no-]embed-source</p></td>
<td><p>Enable/disable embedding source text in DWARF
debug sections. Useful for environments where
source cannot be written to disk, such as
when performing online compilation.</p></td>
</tr>
</tbody>
</table>
</dd>
</dl>
<p>This option enables one extended content types in the DWARF v5 Line Number
Program Header, which is used to encode embedded source.</p>
<blockquote>
<div><table class="docutils align-default" id="amdgpu-dwarf-extended-content-types">
<caption><span class="caption-text">AMDGPU DWARF Line Number Program Header Extended Content Types</span><a class="headerlink" href="#amdgpu-dwarf-extended-content-types" title="Permalink to this table">¶</a></caption>
<colgroup>
<col style="width: 56%" />
<col style="width: 44%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>Content Type</p></th>
<th class="head"><p>Form</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">DW_LNCT_LLVM_source</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">DW_FORM_line_strp</span></code></p></td>
</tr>
</tbody>
</table>
</div></blockquote>
<p>The source field will contain the UTF-8 encoded, null-terminated source text
with <code class="docutils literal notranslate"><span class="pre">'\n'</span></code> line endings. When the source field is present, consumers can use
the embedded source instead of attempting to discover the source on disk. When
the source field is absent, consumers can access the file to get the source
text.</p>
<p>The above content type appears in the <code class="docutils literal notranslate"><span class="pre">file_name_entry_format</span></code> field of the
line table prologue, and its corresponding value appear in the <code class="docutils literal notranslate"><span class="pre">file_names</span></code>
field. The current encoding of the content type is documented in table
<a class="reference internal" href="#amdgpu-dwarf-extended-content-types-encoding"><span class="std std-ref">AMDGPU DWARF Line Number Program Header Extended Content Types Encoding</span></a></p>
<blockquote>
<div><table class="docutils align-default" id="amdgpu-dwarf-extended-content-types-encoding">
<caption><span class="caption-text">AMDGPU DWARF Line Number Program Header Extended Content Types Encoding</span><a class="headerlink" href="#amdgpu-dwarf-extended-content-types-encoding" title="Permalink to this table">¶</a></caption>
<colgroup>
<col style="width: 58%" />
<col style="width: 42%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>Content Type</p></th>
<th class="head"><p>Value</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">DW_LNCT_LLVM_source</span></code></p></td>
<td><p>0x2001</p></td>
</tr>
</tbody>
</table>
</div></blockquote>
</div>
</div>
</div>
<div class="section" id="code-conventions">
<span id="amdgpu-code-conventions"></span><h2><a class="toc-backref" href="#id69">Code Conventions</a><a class="headerlink" href="#code-conventions" title="Permalink to this headline">¶</a></h2>
<p>This section provides code conventions used for each supported target triple OS
(see <a class="reference internal" href="#amdgpu-target-triples"><span class="std std-ref">Target Triples</span></a>).</p>
<div class="section" id="amdhsa">
<h3><a class="toc-backref" href="#id70">AMDHSA</a><a class="headerlink" href="#amdhsa" title="Permalink to this headline">¶</a></h3>
<p>This section provides code conventions used when the target triple OS is
<code class="docutils literal notranslate"><span class="pre">amdhsa</span></code> (see <a class="reference internal" href="#amdgpu-target-triples"><span class="std std-ref">Target Triples</span></a>).</p>
<div class="section" id="code-object-target-identification">
<span id="amdgpu-amdhsa-code-object-target-identification"></span><h4><a class="toc-backref" href="#id71">Code Object Target Identification</a><a class="headerlink" href="#code-object-target-identification" title="Permalink to this headline">¶</a></h4>
<p>The AMDHSA OS uses the following syntax to specify the code object
target as a single string:</p>
<blockquote>
<div><p><code class="docutils literal notranslate"><span class="pre">&lt;Architecture&gt;-&lt;Vendor&gt;-&lt;OS&gt;-&lt;Environment&gt;-&lt;Processor&gt;&lt;Target</span> <span class="pre">Features&gt;</span></code></p>
</div></blockquote>
<p>Where:</p>
<blockquote>
<div><ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">&lt;Architecture&gt;</span></code>, <code class="docutils literal notranslate"><span class="pre">&lt;Vendor&gt;</span></code>, <code class="docutils literal notranslate"><span class="pre">&lt;OS&gt;</span></code> and <code class="docutils literal notranslate"><span class="pre">&lt;Environment&gt;</span></code>
are the same as the <em>Target Triple</em> (see
<a class="reference internal" href="#amdgpu-target-triples"><span class="std std-ref">Target Triples</span></a>).</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">&lt;Processor&gt;</span></code> is the same as the <em>Processor</em> (see
<a class="reference internal" href="#amdgpu-processors"><span class="std std-ref">Processors</span></a>).</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">&lt;Target</span> <span class="pre">Features&gt;</span></code> is a list of the enabled <em>Target Features</em>
(see <a class="reference internal" href="#amdgpu-target-features"><span class="std std-ref">Target Features</span></a>), each prefixed by a plus, that
apply to <em>Processor</em>. The list must be in the same order as listed
in the table <a class="reference internal" href="#amdgpu-target-feature-table"><span class="std std-ref">AMDGPU Target Features</span></a>. Note that <em>Target
Features</em> must be included in the list if they are enabled even if
that is the default for <em>Processor</em>.</p></li>
</ul>
</div></blockquote>
<p>For example:</p>
<blockquote>
<div><p><code class="docutils literal notranslate"><span class="pre">&quot;amdgcn-amd-amdhsa--gfx902+xnack&quot;</span></code></p>
</div></blockquote>
</div>
<div class="section" id="code-object-metadata">
<span id="amdgpu-amdhsa-code-object-metadata"></span><h4><a class="toc-backref" href="#id72">Code Object Metadata</a><a class="headerlink" href="#code-object-metadata" title="Permalink to this headline">¶</a></h4>
<p>The code object metadata specifies extensible metadata associated with the code
objects executed on HSA <a class="reference internal" href="#hsa" id="id26"><span>[HSA]</span></a> compatible runtimes such as AMD’s ROCm
<a class="reference internal" href="#amd-rocm" id="id27"><span>[AMD-ROCm]</span></a>. The encoding and semantics of this metadata depends on the code
object version; see <a class="reference internal" href="#amdgpu-amdhsa-code-object-metadata-v2"><span class="std std-ref">Code Object V2 Metadata (-mattr=-code-object-v3)</span></a> and
<a class="reference internal" href="#amdgpu-amdhsa-code-object-metadata-v3"><span class="std std-ref">Code Object V3 Metadata (-mattr=+code-object-v3)</span></a>.</p>
<p>Code object metadata is specified in a note record (see
<a class="reference internal" href="#amdgpu-note-records"><span class="std std-ref">Note Records</span></a>) and is required when the target triple OS is
<code class="docutils literal notranslate"><span class="pre">amdhsa</span></code> (see <a class="reference internal" href="#amdgpu-target-triples"><span class="std std-ref">Target Triples</span></a>). It must contain the minimum
information necessary to support the ROCM kernel queries. For example, the
segment sizes needed in a dispatch packet. In addition, a high level language
runtime may require other information to be included. For example, the AMD
OpenCL runtime records kernel argument information.</p>
<div class="section" id="code-object-v2-metadata-mattr-code-object-v3">
<span id="amdgpu-amdhsa-code-object-metadata-v2"></span><h5><a class="toc-backref" href="#id73">Code Object V2 Metadata (-mattr=-code-object-v3)</a><a class="headerlink" href="#code-object-v2-metadata-mattr-code-object-v3" title="Permalink to this headline">¶</a></h5>
<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p>Code Object V2 is not the default code object version emitted by
this version of LLVM. For a description of the metadata generated with the
default configuration (Code Object V3) see
<a class="reference internal" href="#amdgpu-amdhsa-code-object-metadata-v3"><span class="std std-ref">Code Object V3 Metadata (-mattr=+code-object-v3)</span></a>.</p>
</div>
<p>Code object V2 metadata is specified by the <code class="docutils literal notranslate"><span class="pre">NT_AMD_AMDGPU_METADATA</span></code> note
record (see <a class="reference internal" href="#amdgpu-note-records-v2"><span class="std std-ref">Code Object V2 Note Records (-mattr=-code-object-v3)</span></a>).</p>
<p>The metadata is specified as a YAML formatted string (see <a class="reference internal" href="#yaml" id="id28"><span>[YAML]</span></a> and
<a class="reference internal" href="YamlIO.html"><span class="doc">YAML I/O</span></a>).</p>
<p>The metadata is represented as a single YAML document comprised of the mapping
defined in table <a class="reference internal" href="#amdgpu-amdhsa-code-object-metadata-map-table-v2"><span class="std std-ref">AMDHSA Code Object V2 Metadata Map</span></a> and
referenced tables.</p>
<p>For boolean values, the string values of <code class="docutils literal notranslate"><span class="pre">false</span></code> and <code class="docutils literal notranslate"><span class="pre">true</span></code> are used for
false and true respectively.</p>
<p>Additional information can be added to the mappings. To avoid conflicts, any
non-AMD key names should be prefixed by “<em>vendor-name</em>.”.</p>
<blockquote>
<div><table class="docutils align-default" id="amdgpu-amdhsa-code-object-metadata-map-table-v2">
<caption><span class="caption-text">AMDHSA Code Object V2 Metadata Map</span><a class="headerlink" href="#amdgpu-amdhsa-code-object-metadata-map-table-v2" title="Permalink to this table">¶</a></caption>
<colgroup>
<col style="width: 11%" />
<col style="width: 15%" />
<col style="width: 10%" />
<col style="width: 65%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>String Key</p></th>
<th class="head"><p>Value Type</p></th>
<th class="head"><p>Required?</p></th>
<th class="head"><p>Description</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>“Version”</p></td>
<td><p>sequence of
2 integers</p></td>
<td><p>Required</p></td>
<td><ul class="simple">
<li><p>The first integer is the major
version. Currently 1.</p></li>
<li><p>The second integer is the minor
version. Currently 0.</p></li>
</ul>
</td>
</tr>
<tr class="row-odd"><td><p>“Printf”</p></td>
<td><p>sequence of
strings</p></td>
<td></td>
<td><p>Each string is encoded information
about a printf function call. The
encoded information is organized as
fields separated by colon (‘:’):</p>
<p><code class="docutils literal notranslate"><span class="pre">ID:N:S[0]:S[1]:...:S[N-1]:FormatString</span></code></p>
<p>where:</p>
<dl class="simple">
<dt><code class="docutils literal notranslate"><span class="pre">ID</span></code></dt><dd><p>A 32 bit integer as a unique id for
each printf function call</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">N</span></code></dt><dd><p>A 32 bit integer equal to the number
of arguments of printf function call
minus 1</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">S[i]</span></code> (where i = 0, 1, … , N-1)</dt><dd><p>32 bit integers for the size in bytes
of the i-th FormatString argument of
the printf function call</p>
</dd>
<dt>FormatString</dt><dd><p>The format string passed to the
printf function call.</p>
</dd>
</dl>
</td>
</tr>
<tr class="row-even"><td><p>“Kernels”</p></td>
<td><p>sequence of
mapping</p></td>
<td><p>Required</p></td>
<td><p>Sequence of the mappings for each
kernel in the code object. See
<a class="reference internal" href="#amdgpu-amdhsa-code-object-kernel-metadata-map-table-v2"><span class="std std-ref">AMDHSA Code Object V2 Kernel Metadata Map</span></a>
for the definition of the mapping.</p></td>
</tr>
</tbody>
</table>
</div></blockquote>
<blockquote>
<div><table class="docutils align-default" id="amdgpu-amdhsa-code-object-kernel-metadata-map-table-v2">
<caption><span class="caption-text">AMDHSA Code Object V2 Kernel Metadata Map</span><a class="headerlink" href="#amdgpu-amdhsa-code-object-kernel-metadata-map-table-v2" title="Permalink to this table">¶</a></caption>
<colgroup>
<col style="width: 15%" />
<col style="width: 12%" />
<col style="width: 8%" />
<col style="width: 66%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>String Key</p></th>
<th class="head"><p>Value Type</p></th>
<th class="head"><p>Required?</p></th>
<th class="head"><p>Description</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>“Name”</p></td>
<td><p>string</p></td>
<td><p>Required</p></td>
<td><p>Source name of the kernel.</p></td>
</tr>
<tr class="row-odd"><td><p>“SymbolName”</p></td>
<td><p>string</p></td>
<td><p>Required</p></td>
<td><p>Name of the kernel
descriptor ELF symbol.</p></td>
</tr>
<tr class="row-even"><td><p>“Language”</p></td>
<td><p>string</p></td>
<td></td>
<td><p>Source language of the kernel.
Values include:</p>
<ul class="simple">
<li><p>“OpenCL C”</p></li>
<li><p>“OpenCL C++”</p></li>
<li><p>“HCC”</p></li>
<li><p>“OpenMP”</p></li>
</ul>
</td>
</tr>
<tr class="row-odd"><td><p>“LanguageVersion”</p></td>
<td><p>sequence of
2 integers</p></td>
<td></td>
<td><ul class="simple">
<li><p>The first integer is the major
version.</p></li>
<li><p>The second integer is the
minor version.</p></li>
</ul>
</td>
</tr>
<tr class="row-even"><td><p>“Attrs”</p></td>
<td><p>mapping</p></td>
<td></td>
<td><p>Mapping of kernel attributes.
See
<a class="reference internal" href="#amdgpu-amdhsa-code-object-kernel-attribute-metadata-map-table-v2"><span class="std std-ref">AMDHSA Code Object V2 Kernel Attribute Metadata Map</span></a>
for the mapping definition.</p></td>
</tr>
<tr class="row-odd"><td><p>“Args”</p></td>
<td><p>sequence of
mapping</p></td>
<td></td>
<td><p>Sequence of mappings of the
kernel arguments. See
<a class="reference internal" href="#amdgpu-amdhsa-code-object-kernel-argument-metadata-map-table-v2"><span class="std std-ref">AMDHSA Code Object V2 Kernel Argument Metadata Map</span></a>
for the definition of the mapping.</p></td>
</tr>
<tr class="row-even"><td><p>“CodeProps”</p></td>
<td><p>mapping</p></td>
<td></td>
<td><p>Mapping of properties related to
the kernel code. See
<a class="reference internal" href="#amdgpu-amdhsa-code-object-kernel-code-properties-metadata-map-table-v2"><span class="std std-ref">AMDHSA Code Object V2 Kernel Code Properties Metadata Map</span></a>
for the mapping definition.</p></td>
</tr>
</tbody>
</table>
</div></blockquote>
<blockquote>
<div><table class="docutils align-default" id="amdgpu-amdhsa-code-object-kernel-attribute-metadata-map-table-v2">
<caption><span class="caption-text">AMDHSA Code Object V2 Kernel Attribute Metadata Map</span><a class="headerlink" href="#amdgpu-amdhsa-code-object-kernel-attribute-metadata-map-table-v2" title="Permalink to this table">¶</a></caption>
<colgroup>
<col style="width: 26%" />
<col style="width: 19%" />
<col style="width: 13%" />
<col style="width: 42%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>String Key</p></th>
<th class="head"><p>Value Type</p></th>
<th class="head"><p>Required?</p></th>
<th class="head"><p>Description</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>“ReqdWorkGroupSize”</p></td>
<td><p>sequence of
3 integers</p></td>
<td></td>
<td><p>If not 0, 0, 0 then all values
must be &gt;=1 and the dispatch
work-group size X, Y, Z must
correspond to the specified
values. Defaults to 0, 0, 0.</p>
<p>Corresponds to the OpenCL
<code class="docutils literal notranslate"><span class="pre">reqd_work_group_size</span></code>
attribute.</p>
</td>
</tr>
<tr class="row-odd"><td><p>“WorkGroupSizeHint”</p></td>
<td><p>sequence of
3 integers</p></td>
<td></td>
<td><p>The dispatch work-group size
X, Y, Z is likely to be the
specified values.</p>
<p>Corresponds to the OpenCL
<code class="docutils literal notranslate"><span class="pre">work_group_size_hint</span></code>
attribute.</p>
</td>
</tr>
<tr class="row-even"><td><p>“VecTypeHint”</p></td>
<td><p>string</p></td>
<td></td>
<td><p>The name of a scalar or vector
type.</p>
<p>Corresponds to the OpenCL
<code class="docutils literal notranslate"><span class="pre">vec_type_hint</span></code> attribute.</p>
</td>
</tr>
<tr class="row-odd"><td><p>“RuntimeHandle”</p></td>
<td><p>string</p></td>
<td></td>
<td><p>The external symbol name
associated with a kernel.
OpenCL runtime allocates a
global buffer for the symbol
and saves the kernel’s address
to it, which is used for
device side enqueueing. Only
available for device side
enqueued kernels.</p></td>
</tr>
</tbody>
</table>
</div></blockquote>
<blockquote>
<div><table class="docutils align-default" id="amdgpu-amdhsa-code-object-kernel-argument-metadata-map-table-v2">
<caption><span class="caption-text">AMDHSA Code Object V2 Kernel Argument Metadata Map</span><a class="headerlink" href="#amdgpu-amdhsa-code-object-kernel-argument-metadata-map-table-v2" title="Permalink to this table">¶</a></caption>
<colgroup>
<col style="width: 22%" />
<col style="width: 18%" />
<col style="width: 12%" />
<col style="width: 49%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>String Key</p></th>
<th class="head"><p>Value Type</p></th>
<th class="head"><p>Required?</p></th>
<th class="head"><p>Description</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>“Name”</p></td>
<td><p>string</p></td>
<td></td>
<td><p>Kernel argument name.</p></td>
</tr>
<tr class="row-odd"><td><p>“TypeName”</p></td>
<td><p>string</p></td>
<td></td>
<td><p>Kernel argument type name.</p></td>
</tr>
<tr class="row-even"><td><p>“Size”</p></td>
<td><p>integer</p></td>
<td><p>Required</p></td>
<td><p>Kernel argument size in bytes.</p></td>
</tr>
<tr class="row-odd"><td><p>“Align”</p></td>
<td><p>integer</p></td>
<td><p>Required</p></td>
<td><p>Kernel argument alignment in
bytes. Must be a power of two.</p></td>
</tr>
<tr class="row-even"><td><p>“ValueKind”</p></td>
<td><p>string</p></td>
<td><p>Required</p></td>
<td><p>Kernel argument kind that
specifies how to set up the
corresponding argument.
Values include:</p>
<dl class="simple">
<dt>“ByValue”</dt><dd><p>The argument is copied
directly into the kernarg.</p>
</dd>
<dt>“GlobalBuffer”</dt><dd><p>A global address space pointer
to the buffer data is passed
in the kernarg.</p>
</dd>
<dt>“DynamicSharedPointer”</dt><dd><p>A group address space pointer
to dynamically allocated LDS
is passed in the kernarg.</p>
</dd>
<dt>“Sampler”</dt><dd><p>A global address space
pointer to a S# is passed in
the kernarg.</p>
</dd>
<dt>“Image”</dt><dd><p>A global address space
pointer to a T# is passed in
the kernarg.</p>
</dd>
<dt>“Pipe”</dt><dd><p>A global address space pointer
to an OpenCL pipe is passed in
the kernarg.</p>
</dd>
<dt>“Queue”</dt><dd><p>A global address space pointer
to an OpenCL device enqueue
queue is passed in the
kernarg.</p>
</dd>
<dt>“HiddenGlobalOffsetX”</dt><dd><p>The OpenCL grid dispatch
global offset for the X
dimension is passed in the
kernarg.</p>
</dd>
<dt>“HiddenGlobalOffsetY”</dt><dd><p>The OpenCL grid dispatch
global offset for the Y
dimension is passed in the
kernarg.</p>
</dd>
<dt>“HiddenGlobalOffsetZ”</dt><dd><p>The OpenCL grid dispatch
global offset for the Z
dimension is passed in the
kernarg.</p>
</dd>
<dt>“HiddenNone”</dt><dd><p>An argument that is not used
by the kernel. Space needs to
be left for it, but it does
not need to be set up.</p>
</dd>
<dt>“HiddenPrintfBuffer”</dt><dd><p>A global address space pointer
to the runtime printf buffer
is passed in kernarg.</p>
</dd>
<dt>“HiddenDefaultQueue”</dt><dd><p>A global address space pointer
to the OpenCL device enqueue
queue that should be used by
the kernel by default is
passed in the kernarg.</p>
</dd>
<dt>“HiddenCompletionAction”</dt><dd><p>A global address space pointer
to help link enqueued kernels into
the ancestor tree for determining
when the parent kernel has finished.</p>
</dd>
<dt>“HiddenMultiGridSyncArg”</dt><dd><p>A global address space pointer for
multi-grid synchronization is
passed in the kernarg.</p>
</dd>
</dl>
</td>
</tr>
<tr class="row-odd"><td><p>“ValueType”</p></td>
<td><p>string</p></td>
<td><p>Required</p></td>
<td><p>Kernel argument value type. Only
present if “ValueKind” is
“ByValue”. For vector data
types, the value is for the
element type. Values include:</p>
<ul class="simple">
<li><p>“Struct”</p></li>
<li><p>“I8”</p></li>
<li><p>“U8”</p></li>
<li><p>“I16”</p></li>
<li><p>“U16”</p></li>
<li><p>“F16”</p></li>
<li><p>“I32”</p></li>
<li><p>“U32”</p></li>
<li><p>“F32”</p></li>
<li><p>“I64”</p></li>
<li><p>“U64”</p></li>
<li><p>“F64”</p></li>
</ul>
</td>
</tr>
<tr class="row-even"><td><p>“PointeeAlign”</p></td>
<td><p>integer</p></td>
<td></td>
<td><p>Alignment in bytes of pointee
type for pointer type kernel
argument. Must be a power
of 2. Only present if
“ValueKind” is
“DynamicSharedPointer”.</p></td>
</tr>
<tr class="row-odd"><td><p>“AddrSpaceQual”</p></td>
<td><p>string</p></td>
<td></td>
<td><p>Kernel argument address space
qualifier. Only present if
“ValueKind” is “GlobalBuffer” or
“DynamicSharedPointer”. Values
are:</p>
<ul class="simple">
<li><p>“Private”</p></li>
<li><p>“Global”</p></li>
<li><p>“Constant”</p></li>
<li><p>“Local”</p></li>
<li><p>“Generic”</p></li>
<li><p>“Region”</p></li>
</ul>
</td>
</tr>
<tr class="row-even"><td><p>“AccQual”</p></td>
<td><p>string</p></td>
<td></td>
<td><p>Kernel argument access
qualifier. Only present if
“ValueKind” is “Image” or
“Pipe”. Values
are:</p>
<ul class="simple">
<li><p>“ReadOnly”</p></li>
<li><p>“WriteOnly”</p></li>
<li><p>“ReadWrite”</p></li>
</ul>
</td>
</tr>
<tr class="row-odd"><td><p>“ActualAccQual”</p></td>
<td><p>string</p></td>
<td></td>
<td><p>The actual memory accesses
performed by the kernel on the
kernel argument. Only present if
“ValueKind” is “GlobalBuffer”,
“Image”, or “Pipe”. This may be
more restrictive than indicated
by “AccQual” to reflect what the
kernel actual does. If not
present then the runtime must
assume what is implied by
“AccQual” and “IsConst”. Values
are:</p>
<ul class="simple">
<li><p>“ReadOnly”</p></li>
<li><p>“WriteOnly”</p></li>
<li><p>“ReadWrite”</p></li>
</ul>
</td>
</tr>
<tr class="row-even"><td><p>“IsConst”</p></td>
<td><p>boolean</p></td>
<td></td>
<td><p>Indicates if the kernel argument
is const qualified. Only present
if “ValueKind” is
“GlobalBuffer”.</p></td>
</tr>
<tr class="row-odd"><td><p>“IsRestrict”</p></td>
<td><p>boolean</p></td>
<td></td>
<td><p>Indicates if the kernel argument
is restrict qualified. Only
present if “ValueKind” is
“GlobalBuffer”.</p></td>
</tr>
<tr class="row-even"><td><p>“IsVolatile”</p></td>
<td><p>boolean</p></td>
<td></td>
<td><p>Indicates if the kernel argument
is volatile qualified. Only
present if “ValueKind” is
“GlobalBuffer”.</p></td>
</tr>
<tr class="row-odd"><td><p>“IsPipe”</p></td>
<td><p>boolean</p></td>
<td></td>
<td><p>Indicates if the kernel argument
is pipe qualified. Only present
if “ValueKind” is “Pipe”.</p>
</td>
</tr>
</tbody>
</table>
</div></blockquote>
<blockquote>
<div><table class="docutils align-default" id="amdgpu-amdhsa-code-object-kernel-code-properties-metadata-map-table-v2">
<caption><span class="caption-text">AMDHSA Code Object V2 Kernel Code Properties Metadata Map</span><a class="headerlink" href="#amdgpu-amdhsa-code-object-kernel-code-properties-metadata-map-table-v2" title="Permalink to this table">¶</a></caption>
<colgroup>
<col style="width: 39%" />
<col style="width: 19%" />
<col style="width: 13%" />
<col style="width: 29%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>String Key</p></th>
<th class="head"><p>Value Type</p></th>
<th class="head"><p>Required?</p></th>
<th class="head"><p>Description</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>“KernargSegmentSize”</p></td>
<td><p>integer</p></td>
<td><p>Required</p></td>
<td><p>The size in bytes of
the kernarg segment
that holds the values
of the arguments to
the kernel.</p></td>
</tr>
<tr class="row-odd"><td><p>“GroupSegmentFixedSize”</p></td>
<td><p>integer</p></td>
<td><p>Required</p></td>
<td><p>The amount of group
segment memory
required by a
work-group in
bytes. This does not
include any
dynamically allocated
group segment memory
that may be added
when the kernel is
dispatched.</p></td>
</tr>
<tr class="row-even"><td><p>“PrivateSegmentFixedSize”</p></td>
<td><p>integer</p></td>
<td><p>Required</p></td>
<td><p>The amount of fixed
private address space
memory required for a
work-item in
bytes. If the kernel
uses a dynamic call
stack then additional
space must be added
to this value for the
call stack.</p></td>
</tr>
<tr class="row-odd"><td><p>“KernargSegmentAlign”</p></td>
<td><p>integer</p></td>
<td><p>Required</p></td>
<td><p>The maximum byte
alignment of
arguments in the
kernarg segment. Must
be a power of 2.</p></td>
</tr>
<tr class="row-even"><td><p>“WavefrontSize”</p></td>
<td><p>integer</p></td>
<td><p>Required</p></td>
<td><p>Wavefront size. Must
be a power of 2.</p></td>
</tr>
<tr class="row-odd"><td><p>“NumSGPRs”</p></td>
<td><p>integer</p></td>
<td><p>Required</p></td>
<td><p>Number of scalar
registers used by a
wavefront for
GFX6-GFX10. This
includes the special
SGPRs for VCC, Flat
Scratch (GFX7-GFX10)
and XNACK (for
GFX8-GFX10). It does
not include the 16
SGPR added if a trap
handler is
enabled. It is not
rounded up to the
allocation
granularity.</p></td>
</tr>
<tr class="row-even"><td><p>“NumVGPRs”</p></td>
<td><p>integer</p></td>
<td><p>Required</p></td>
<td><p>Number of vector
registers used by
each work-item for
GFX6-GFX10</p></td>
</tr>
<tr class="row-odd"><td><p>“MaxFlatWorkGroupSize”</p></td>
<td><p>integer</p></td>
<td><p>Required</p></td>
<td><p>Maximum flat
work-group size
supported by the
kernel in work-items.
Must be &gt;=1 and
consistent with
ReqdWorkGroupSize if
not 0, 0, 0.</p></td>
</tr>
<tr class="row-even"><td><p>“NumSpilledSGPRs”</p></td>
<td><p>integer</p></td>
<td></td>
<td><p>Number of stores from
a scalar register to
a register allocator
created spill
location.</p></td>
</tr>
<tr class="row-odd"><td><p>“NumSpilledVGPRs”</p></td>
<td><p>integer</p></td>
<td></td>
<td><p>Number of stores from
a vector register to
a register allocator
created spill
location.</p></td>
</tr>
</tbody>
</table>
</div></blockquote>
</div>
<div class="section" id="code-object-v3-metadata-mattr-code-object-v3">
<span id="amdgpu-amdhsa-code-object-metadata-v3"></span><h5><a class="toc-backref" href="#id74">Code Object V3 Metadata (-mattr=+code-object-v3)</a><a class="headerlink" href="#code-object-v3-metadata-mattr-code-object-v3" title="Permalink to this headline">¶</a></h5>
<p>Code object V3 metadata is specified by the <code class="docutils literal notranslate"><span class="pre">NT_AMDGPU_METADATA</span></code> note record
(see <a class="reference internal" href="#amdgpu-note-records-v3"><span class="std std-ref">Code Object V3 Note Records (-mattr=+code-object-v3)</span></a>).</p>
<p>The metadata is represented as Message Pack formatted binary data (see
<a class="reference internal" href="#msgpack" id="id29"><span>[MsgPack]</span></a>). The top level is a Message Pack map that includes the
keys defined in table
<a class="reference internal" href="#amdgpu-amdhsa-code-object-metadata-map-table-v3"><span class="std std-ref">AMDHSA Code Object V3 Metadata Map</span></a> and referenced
tables.</p>
<p>Additional information can be added to the maps. To avoid conflicts,
any key names should be prefixed by “<em>vendor-name</em>.” where
<code class="docutils literal notranslate"><span class="pre">vendor-name</span></code> can be the the name of the vendor and specific vendor
tool that generates the information. The prefix is abbreviated to
simply “.” when it appears within a map that has been added by the
same <em>vendor-name</em>.</p>
<blockquote>
<div><table class="docutils align-default" id="amdgpu-amdhsa-code-object-metadata-map-table-v3">
<caption><span class="caption-text">AMDHSA Code Object V3 Metadata Map</span><a class="headerlink" href="#amdgpu-amdhsa-code-object-metadata-map-table-v3" title="Permalink to this table">¶</a></caption>
<colgroup>
<col style="width: 17%" />
<col style="width: 14%" />
<col style="width: 9%" />
<col style="width: 60%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>String Key</p></th>
<th class="head"><p>Value Type</p></th>
<th class="head"><p>Required?</p></th>
<th class="head"><p>Description</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>“amdhsa.version”</p></td>
<td><p>sequence of
2 integers</p></td>
<td><p>Required</p></td>
<td><ul class="simple">
<li><p>The first integer is the major
version. Currently 1.</p></li>
<li><p>The second integer is the minor
version. Currently 0.</p></li>
</ul>
</td>
</tr>
<tr class="row-odd"><td><p>“amdhsa.printf”</p></td>
<td><p>sequence of
strings</p></td>
<td></td>
<td><p>Each string is encoded information
about a printf function call. The
encoded information is organized as
fields separated by colon (‘:’):</p>
<p><code class="docutils literal notranslate"><span class="pre">ID:N:S[0]:S[1]:...:S[N-1]:FormatString</span></code></p>
<p>where:</p>
<dl class="simple">
<dt><code class="docutils literal notranslate"><span class="pre">ID</span></code></dt><dd><p>A 32 bit integer as a unique id for
each printf function call</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">N</span></code></dt><dd><p>A 32 bit integer equal to the number
of arguments of printf function call
minus 1</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">S[i]</span></code> (where i = 0, 1, … , N-1)</dt><dd><p>32 bit integers for the size in bytes
of the i-th FormatString argument of
the printf function call</p>
</dd>
<dt>FormatString</dt><dd><p>The format string passed to the
printf function call.</p>
</dd>
</dl>
</td>
</tr>
<tr class="row-even"><td><p>“amdhsa.kernels”</p></td>
<td><p>sequence of
map</p></td>
<td><p>Required</p></td>
<td><p>Sequence of the maps for each
kernel in the code object. See
<a class="reference internal" href="#amdgpu-amdhsa-code-object-kernel-metadata-map-table-v3"><span class="std std-ref">AMDHSA Code Object V3 Kernel Metadata Map</span></a>
for the definition of the keys included
in that map.</p></td>
</tr>
</tbody>
</table>
</div></blockquote>
<blockquote>
<div><table class="docutils align-default" id="amdgpu-amdhsa-code-object-kernel-metadata-map-table-v3">
<caption><span class="caption-text">AMDHSA Code Object V3 Kernel Metadata Map</span><a class="headerlink" href="#amdgpu-amdhsa-code-object-kernel-metadata-map-table-v3" title="Permalink to this table">¶</a></caption>
<colgroup>
<col style="width: 27%" />
<col style="width: 11%" />
<col style="width: 7%" />
<col style="width: 55%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>String Key</p></th>
<th class="head"><p>Value Type</p></th>
<th class="head"><p>Required?</p></th>
<th class="head"><p>Description</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>“.name”</p></td>
<td><p>string</p></td>
<td><p>Required</p></td>
<td><p>Source name of the kernel.</p></td>
</tr>
<tr class="row-odd"><td><p>“.symbol”</p></td>
<td><p>string</p></td>
<td><p>Required</p></td>
<td><p>Name of the kernel
descriptor ELF symbol.</p></td>
</tr>
<tr class="row-even"><td><p>“.language”</p></td>
<td><p>string</p></td>
<td></td>
<td><p>Source language of the kernel.
Values include:</p>
<ul class="simple">
<li><p>“OpenCL C”</p></li>
<li><p>“OpenCL C++”</p></li>
<li><p>“HCC”</p></li>
<li><p>“HIP”</p></li>
<li><p>“OpenMP”</p></li>
<li><p>“Assembler”</p></li>
</ul>
</td>
</tr>
<tr class="row-odd"><td><p>“.language_version”</p></td>
<td><p>sequence of
2 integers</p></td>
<td></td>
<td><ul class="simple">
<li><p>The first integer is the major
version.</p></li>
<li><p>The second integer is the
minor version.</p></li>
</ul>
</td>
</tr>
<tr class="row-even"><td><p>“.args”</p></td>
<td><p>sequence of
map</p></td>
<td></td>
<td><p>Sequence of maps of the
kernel arguments. See
<a class="reference internal" href="#amdgpu-amdhsa-code-object-kernel-argument-metadata-map-table-v3"><span class="std std-ref">AMDHSA Code Object V3 Kernel Argument Metadata Map</span></a>
for the definition of the keys
included in that map.</p></td>
</tr>
<tr class="row-odd"><td><p>“.reqd_workgroup_size”</p></td>
<td><p>sequence of
3 integers</p></td>
<td></td>
<td><p>If not 0, 0, 0 then all values
must be &gt;=1 and the dispatch
work-group size X, Y, Z must
correspond to the specified
values. Defaults to 0, 0, 0.</p>
<p>Corresponds to the OpenCL
<code class="docutils literal notranslate"><span class="pre">reqd_work_group_size</span></code>
attribute.</p>
</td>
</tr>
<tr class="row-even"><td><p>“.workgroup_size_hint”</p></td>
<td><p>sequence of
3 integers</p></td>
<td></td>
<td><p>The dispatch work-group size
X, Y, Z is likely to be the
specified values.</p>
<p>Corresponds to the OpenCL
<code class="docutils literal notranslate"><span class="pre">work_group_size_hint</span></code>
attribute.</p>
</td>
</tr>
<tr class="row-odd"><td><p>“.vec_type_hint”</p></td>
<td><p>string</p></td>
<td></td>
<td><p>The name of a scalar or vector
type.</p>
<p>Corresponds to the OpenCL
<code class="docutils literal notranslate"><span class="pre">vec_type_hint</span></code> attribute.</p>
</td>
</tr>
<tr class="row-even"><td><p>“.device_enqueue_symbol”</p></td>
<td><p>string</p></td>
<td></td>
<td><p>The external symbol name
associated with a kernel.
OpenCL runtime allocates a
global buffer for the symbol
and saves the kernel’s address
to it, which is used for
device side enqueueing. Only
available for device side
enqueued kernels.</p></td>
</tr>
<tr class="row-odd"><td><p>“.kernarg_segment_size”</p></td>
<td><p>integer</p></td>
<td><p>Required</p></td>
<td><p>The size in bytes of
the kernarg segment
that holds the values
of the arguments to
the kernel.</p></td>
</tr>
<tr class="row-even"><td><p>“.group_segment_fixed_size”</p></td>
<td><p>integer</p></td>
<td><p>Required</p></td>
<td><p>The amount of group
segment memory
required by a
work-group in
bytes. This does not
include any
dynamically allocated
group segment memory
that may be added
when the kernel is
dispatched.</p></td>
</tr>
<tr class="row-odd"><td><p>“.private_segment_fixed_size”</p></td>
<td><p>integer</p></td>
<td><p>Required</p></td>
<td><p>The amount of fixed
private address space
memory required for a
work-item in
bytes. If the kernel
uses a dynamic call
stack then additional
space must be added
to this value for the
call stack.</p></td>
</tr>
<tr class="row-even"><td><p>“.kernarg_segment_align”</p></td>
<td><p>integer</p></td>
<td><p>Required</p></td>
<td><p>The maximum byte
alignment of
arguments in the
kernarg segment. Must
be a power of 2.</p></td>
</tr>
<tr class="row-odd"><td><p>“.wavefront_size”</p></td>
<td><p>integer</p></td>
<td><p>Required</p></td>
<td><p>Wavefront size. Must
be a power of 2.</p></td>
</tr>
<tr class="row-even"><td><p>“.sgpr_count”</p></td>
<td><p>integer</p></td>
<td><p>Required</p></td>
<td><p>Number of scalar
registers required by a
wavefront for
GFX6-GFX9. A register
is required if it is
used explicitly, or
if a higher numbered
register is used
explicitly. This
includes the special
SGPRs for VCC, Flat
Scratch (GFX7-GFX9)
and XNACK (for
GFX8-GFX9). It does
not include the 16
SGPR added if a trap
handler is
enabled. It is not
rounded up to the
allocation
granularity.</p></td>
</tr>
<tr class="row-odd"><td><p>“.vgpr_count”</p></td>
<td><p>integer</p></td>
<td><p>Required</p></td>
<td><p>Number of vector
registers required by
each work-item for
GFX6-GFX9. A register
is required if it is
used explicitly, or
if a higher numbered
register is used
explicitly.</p></td>
</tr>
<tr class="row-even"><td><p>“.max_flat_workgroup_size”</p></td>
<td><p>integer</p></td>
<td><p>Required</p></td>
<td><p>Maximum flat
work-group size
supported by the
kernel in work-items.
Must be &gt;=1 and
consistent with
ReqdWorkGroupSize if
not 0, 0, 0.</p></td>
</tr>
<tr class="row-odd"><td><p>“.sgpr_spill_count”</p></td>
<td><p>integer</p></td>
<td></td>
<td><p>Number of stores from
a scalar register to
a register allocator
created spill
location.</p></td>
</tr>
<tr class="row-even"><td><p>“.vgpr_spill_count”</p></td>
<td><p>integer</p></td>
<td></td>
<td><p>Number of stores from
a vector register to
a register allocator
created spill
location.</p></td>
</tr>
</tbody>
</table>
</div></blockquote>
<blockquote>
<div><table class="docutils align-default" id="amdgpu-amdhsa-code-object-kernel-argument-metadata-map-table-v3">
<caption><span class="caption-text">AMDHSA Code Object V3 Kernel Argument Metadata Map</span><a class="headerlink" href="#amdgpu-amdhsa-code-object-kernel-argument-metadata-map-table-v3" title="Permalink to this table">¶</a></caption>
<colgroup>
<col style="width: 26%" />
<col style="width: 17%" />
<col style="width: 11%" />
<col style="width: 46%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>String Key</p></th>
<th class="head"><p>Value Type</p></th>
<th class="head"><p>Required?</p></th>
<th class="head"><p>Description</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>“.name”</p></td>
<td><p>string</p></td>
<td></td>
<td><p>Kernel argument name.</p></td>
</tr>
<tr class="row-odd"><td><p>“.type_name”</p></td>
<td><p>string</p></td>
<td></td>
<td><p>Kernel argument type name.</p></td>
</tr>
<tr class="row-even"><td><p>“.size”</p></td>
<td><p>integer</p></td>
<td><p>Required</p></td>
<td><p>Kernel argument size in bytes.</p></td>
</tr>
<tr class="row-odd"><td><p>“.offset”</p></td>
<td><p>integer</p></td>
<td><p>Required</p></td>
<td><p>Kernel argument offset in
bytes. The offset must be a
multiple of the alignment
required by the argument.</p></td>
</tr>
<tr class="row-even"><td><p>“.value_kind”</p></td>
<td><p>string</p></td>
<td><p>Required</p></td>
<td><p>Kernel argument kind that
specifies how to set up the
corresponding argument.
Values include:</p>
<dl class="simple">
<dt>“by_value”</dt><dd><p>The argument is copied
directly into the kernarg.</p>
</dd>
<dt>“global_buffer”</dt><dd><p>A global address space pointer
to the buffer data is passed
in the kernarg.</p>
</dd>
<dt>“dynamic_shared_pointer”</dt><dd><p>A group address space pointer
to dynamically allocated LDS
is passed in the kernarg.</p>
</dd>
<dt>“sampler”</dt><dd><p>A global address space
pointer to a S# is passed in
the kernarg.</p>
</dd>
<dt>“image”</dt><dd><p>A global address space
pointer to a T# is passed in
the kernarg.</p>
</dd>
<dt>“pipe”</dt><dd><p>A global address space pointer
to an OpenCL pipe is passed in
the kernarg.</p>
</dd>
<dt>“queue”</dt><dd><p>A global address space pointer
to an OpenCL device enqueue
queue is passed in the
kernarg.</p>
</dd>
<dt>“hidden_global_offset_x”</dt><dd><p>The OpenCL grid dispatch
global offset for the X
dimension is passed in the
kernarg.</p>
</dd>
<dt>“hidden_global_offset_y”</dt><dd><p>The OpenCL grid dispatch
global offset for the Y
dimension is passed in the
kernarg.</p>
</dd>
<dt>“hidden_global_offset_z”</dt><dd><p>The OpenCL grid dispatch
global offset for the Z
dimension is passed in the
kernarg.</p>
</dd>
<dt>“hidden_none”</dt><dd><p>An argument that is not used
by the kernel. Space needs to
be left for it, but it does
not need to be set up.</p>
</dd>
<dt>“hidden_printf_buffer”</dt><dd><p>A global address space pointer
to the runtime printf buffer
is passed in kernarg.</p>
</dd>
<dt>“hidden_default_queue”</dt><dd><p>A global address space pointer
to the OpenCL device enqueue
queue that should be used by
the kernel by default is
passed in the kernarg.</p>
</dd>
<dt>“hidden_completion_action”</dt><dd><p>A global address space pointer
to help link enqueued kernels into
the ancestor tree for determining
when the parent kernel has finished.</p>
</dd>
<dt>“hidden_multigrid_sync_arg”</dt><dd><p>A global address space pointer for
multi-grid synchronization is
passed in the kernarg.</p>
</dd>
</dl>
</td>
</tr>
<tr class="row-odd"><td><p>“.value_type”</p></td>
<td><p>string</p></td>
<td><p>Required</p></td>
<td><p>Kernel argument value type. Only
present if “.value_kind” is
“by_value”. For vector data
types, the value is for the
element type. Values include:</p>
<ul class="simple">
<li><p>“struct”</p></li>
<li><p>“i8”</p></li>
<li><p>“u8”</p></li>
<li><p>“i16”</p></li>
<li><p>“u16”</p></li>
<li><p>“f16”</p></li>
<li><p>“i32”</p></li>
<li><p>“u32”</p></li>
<li><p>“f32”</p></li>
<li><p>“i64”</p></li>
<li><p>“u64”</p></li>
<li><p>“f64”</p></li>
</ul>
</td>
</tr>
<tr class="row-even"><td><p>“.pointee_align”</p></td>
<td><p>integer</p></td>
<td></td>
<td><p>Alignment in bytes of pointee
type for pointer type kernel
argument. Must be a power
of 2. Only present if
“.value_kind” is
“dynamic_shared_pointer”.</p></td>
</tr>
<tr class="row-odd"><td><p>“.address_space”</p></td>
<td><p>string</p></td>
<td></td>
<td><p>Kernel argument address space
qualifier. Only present if
“.value_kind” is “global_buffer” or
“dynamic_shared_pointer”. Values
are:</p>
<ul class="simple">
<li><p>“private”</p></li>
<li><p>“global”</p></li>
<li><p>“constant”</p></li>
<li><p>“local”</p></li>
<li><p>“generic”</p></li>
<li><p>“region”</p></li>
</ul>
</td>
</tr>
<tr class="row-even"><td><p>“.access”</p></td>
<td><p>string</p></td>
<td></td>
<td><p>Kernel argument access
qualifier. Only present if
“.value_kind” is “image” or
“pipe”. Values
are:</p>
<ul class="simple">
<li><p>“read_only”</p></li>
<li><p>“write_only”</p></li>
<li><p>“read_write”</p></li>
</ul>
</td>
</tr>
<tr class="row-odd"><td><p>“.actual_access”</p></td>
<td><p>string</p></td>
<td></td>
<td><p>The actual memory accesses
performed by the kernel on the
kernel argument. Only present if
“.value_kind” is “global_buffer”,
“image”, or “pipe”. This may be
more restrictive than indicated
by “.access” to reflect what the
kernel actual does. If not
present then the runtime must
assume what is implied by
“.access” and “.is_const”      . Values
are:</p>
<ul class="simple">
<li><p>“read_only”</p></li>
<li><p>“write_only”</p></li>
<li><p>“read_write”</p></li>
</ul>
</td>
</tr>
<tr class="row-even"><td><p>“.is_const”</p></td>
<td><p>boolean</p></td>
<td></td>
<td><p>Indicates if the kernel argument
is const qualified. Only present
if “.value_kind” is
“global_buffer”.</p></td>
</tr>
<tr class="row-odd"><td><p>“.is_restrict”</p></td>
<td><p>boolean</p></td>
<td></td>
<td><p>Indicates if the kernel argument
is restrict qualified. Only
present if “.value_kind” is
“global_buffer”.</p></td>
</tr>
<tr class="row-even"><td><p>“.is_volatile”</p></td>
<td><p>boolean</p></td>
<td></td>
<td><p>Indicates if the kernel argument
is volatile qualified. Only
present if “.value_kind” is
“global_buffer”.</p></td>
</tr>
<tr class="row-odd"><td><p>“.is_pipe”</p></td>
<td><p>boolean</p></td>
<td></td>
<td><p>Indicates if the kernel argument
is pipe qualified. Only present
if “.value_kind” is “pipe”.</p>
</td>
</tr>
</tbody>
</table>
</div></blockquote>
</div>
</div>
<div class="section" id="kernel-dispatch">
<h4><a class="toc-backref" href="#id75">Kernel Dispatch</a><a class="headerlink" href="#kernel-dispatch" title="Permalink to this headline">¶</a></h4>
<p>The HSA architected queuing language (AQL) defines a user space memory interface
that can be used to control the dispatch of kernels, in an agent independent
way. An agent can have zero or more AQL queues created for it using the ROCm
runtime, in which AQL packets (all of which are 64 bytes) can be placed. See the
<em>HSA Platform System Architecture Specification</em> <a class="reference internal" href="#hsa" id="id30"><span>[HSA]</span></a> for the AQL queue
mechanics and packet layouts.</p>
<p>The packet processor of a kernel agent is responsible for detecting and
dispatching HSA kernels from the AQL queues associated with it. For AMD GPUs the
packet processor is implemented by the hardware command processor (CP),
asynchronous dispatch controller (ADC) and shader processor input controller
(SPI).</p>
<p>The ROCm runtime can be used to allocate an AQL queue object. It uses the kernel
mode driver to initialize and register the AQL queue with CP.</p>
<p>To dispatch a kernel the following actions are performed. This can occur in the
CPU host program, or from an HSA kernel executing on a GPU.</p>
<ol class="arabic simple">
<li><p>A pointer to an AQL queue for the kernel agent on which the kernel is to be
executed is obtained.</p></li>
<li><p>A pointer to the kernel descriptor (see
<a class="reference internal" href="#amdgpu-amdhsa-kernel-descriptor"><span class="std std-ref">Kernel Descriptor</span></a>) of the kernel to execute is
obtained. It must be for a kernel that is contained in a code object that that
was loaded by the ROCm runtime on the kernel agent with which the AQL queue is
associated.</p></li>
<li><p>Space is allocated for the kernel arguments using the ROCm runtime allocator
for a memory region with the kernarg property for the kernel agent that will
execute the kernel. It must be at least 16 byte aligned.</p></li>
<li><p>Kernel argument values are assigned to the kernel argument memory
allocation. The layout is defined in the <em>HSA Programmer’s Language Reference</em>
<a class="reference internal" href="#hsa" id="id31"><span>[HSA]</span></a>. For AMDGPU the kernel execution directly accesses the kernel argument
memory in the same way constant memory is accessed. (Note that the HSA
specification allows an implementation to copy the kernel argument contents to
another location that is accessed by the kernel.)</p></li>
<li><p>An AQL kernel dispatch packet is created on the AQL queue. The ROCm runtime
api uses 64 bit atomic operations to reserve space in the AQL queue for the
packet. The packet must be set up, and the final write must use an atomic
store release to set the packet kind to ensure the packet contents are
visible to the kernel agent. AQL defines a doorbell signal mechanism to
notify the kernel agent that the AQL queue has been updated. These rules, and
the layout of the AQL queue and kernel dispatch packet is defined in the <em>HSA
System Architecture Specification</em> <a class="reference internal" href="#hsa" id="id32"><span>[HSA]</span></a>.</p></li>
<li><p>A kernel dispatch packet includes information about the actual dispatch,
such as grid and work-group size, together with information from the code
object about the kernel, such as segment sizes. The ROCm runtime queries on
the kernel symbol can be used to obtain the code object values which are
recorded in the <a class="reference internal" href="#amdgpu-amdhsa-code-object-metadata"><span class="std std-ref">Code Object Metadata</span></a>.</p></li>
<li><p>CP executes micro-code and is responsible for detecting and setting up the
GPU to execute the wavefronts of a kernel dispatch.</p></li>
<li><p>CP ensures that when the a wavefront starts executing the kernel machine
code, the scalar general purpose registers (SGPR) and vector general purpose
registers (VGPR) are set up as required by the machine code. The required
setup is defined in the <a class="reference internal" href="#amdgpu-amdhsa-kernel-descriptor"><span class="std std-ref">Kernel Descriptor</span></a>. The initial
register state is defined in
<a class="reference internal" href="#amdgpu-amdhsa-initial-kernel-execution-state"><span class="std std-ref">Initial Kernel Execution State</span></a>.</p></li>
<li><p>The prolog of the kernel machine code (see
<a class="reference internal" href="#amdgpu-amdhsa-kernel-prolog"><span class="std std-ref">Kernel Prolog</span></a>) sets up the machine state as necessary
before continuing executing the machine code that corresponds to the kernel.</p></li>
<li><p>When the kernel dispatch has completed execution, CP signals the completion
signal specified in the kernel dispatch packet if not 0.</p></li>
</ol>
</div>
<div class="section" id="memory-spaces">
<span id="amdgpu-amdhsa-memory-spaces"></span><h4><a class="toc-backref" href="#id76">Memory Spaces</a><a class="headerlink" href="#memory-spaces" title="Permalink to this headline">¶</a></h4>
<p>The memory space properties are:</p>
<blockquote>
<div><table class="docutils align-default" id="amdgpu-amdhsa-memory-spaces-table">
<caption><span class="caption-text">AMDHSA Memory Spaces</span><a class="headerlink" href="#amdgpu-amdhsa-memory-spaces-table" title="Permalink to this table">¶</a></caption>
<colgroup>
<col style="width: 28%" />
<col style="width: 18%" />
<col style="width: 13%" />
<col style="width: 11%" />
<col style="width: 30%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>Memory Space Name</p></th>
<th class="head"><p>HSA Segment
Name</p></th>
<th class="head"><p>Hardware
Name</p></th>
<th class="head"><p>Address
Size</p></th>
<th class="head"><p>NULL Value</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>Private</p></td>
<td><p>private</p></td>
<td><p>scratch</p></td>
<td><p>32</p></td>
<td><p>0x00000000</p></td>
</tr>
<tr class="row-odd"><td><p>Local</p></td>
<td><p>group</p></td>
<td><p>LDS</p></td>
<td><p>32</p></td>
<td><p>0xFFFFFFFF</p></td>
</tr>
<tr class="row-even"><td><p>Global</p></td>
<td><p>global</p></td>
<td><p>global</p></td>
<td><p>64</p></td>
<td><p>0x0000000000000000</p></td>
</tr>
<tr class="row-odd"><td><p>Constant</p></td>
<td><p>constant</p></td>
<td><p><em>same as
global</em></p></td>
<td><p>64</p></td>
<td><p>0x0000000000000000</p></td>
</tr>
<tr class="row-even"><td><p>Generic</p></td>
<td><p>flat</p></td>
<td><p>flat</p></td>
<td><p>64</p></td>
<td><p>0x0000000000000000</p></td>
</tr>
<tr class="row-odd"><td><p>Region</p></td>
<td><p>N/A</p></td>
<td><p>GDS</p></td>
<td><p>32</p></td>
<td><p><em>not implemented
for AMDHSA</em></p></td>
</tr>
</tbody>
</table>
</div></blockquote>
<p>The global and constant memory spaces both use global virtual addresses, which
are the same virtual address space used by the CPU. However, some virtual
addresses may only be accessible to the CPU, some only accessible by the GPU,
and some by both.</p>
<p>Using the constant memory space indicates that the data will not change during
the execution of the kernel. This allows scalar read instructions to be
used. The vector and scalar L1 caches are invalidated of volatile data before
each kernel dispatch execution to allow constant memory to change values between
kernel dispatches.</p>
<p>The local memory space uses the hardware Local Data Store (LDS) which is
automatically allocated when the hardware creates work-groups of wavefronts, and
freed when all the wavefronts of a work-group have terminated. The data store
(DS) instructions can be used to access it.</p>
<p>The private memory space uses the hardware scratch memory support. If the kernel
uses scratch, then the hardware allocates memory that is accessed using
wavefront lane dword (4 byte) interleaving. The mapping used from private
address to physical address is:</p>
<blockquote>
<div><p><code class="docutils literal notranslate"><span class="pre">wavefront-scratch-base</span> <span class="pre">+</span>
<span class="pre">(private-address</span> <span class="pre">*</span> <span class="pre">wavefront-size</span> <span class="pre">*</span> <span class="pre">4)</span> <span class="pre">+</span>
<span class="pre">(wavefront-lane-id</span> <span class="pre">*</span> <span class="pre">4)</span></code></p>
</div></blockquote>
<p>There are different ways that the wavefront scratch base address is determined
by a wavefront (see <a class="reference internal" href="#amdgpu-amdhsa-initial-kernel-execution-state"><span class="std std-ref">Initial Kernel Execution State</span></a>). This
memory can be accessed in an interleaved manner using buffer instruction with
the scratch buffer descriptor and per wavefront scratch offset, by the scratch
instructions, or by flat instructions. If each lane of a wavefront accesses the
same private address, the interleaving results in adjacent dwords being accessed
and hence requires fewer cache lines to be fetched. Multi-dword access is not
supported except by flat and scratch instructions in GFX9-GFX10.</p>
<p>The generic address space uses the hardware flat address support available in
GFX7-GFX10. This uses two fixed ranges of virtual addresses (the private and
local appertures), that are outside the range of addressible global memory, to
map from a flat address to a private or local address.</p>
<p>FLAT instructions can take a flat address and access global, private (scratch)
and group (LDS) memory depending in if the address is within one of the
apperture ranges. Flat access to scratch requires hardware aperture setup and
setup in the kernel prologue (see <a class="reference internal" href="#amdgpu-amdhsa-flat-scratch"><span class="std std-ref">Flat Scratch</span></a>). Flat
access to LDS requires hardware aperture setup and M0 (GFX7-GFX8) register setup
(see <a class="reference internal" href="#amdgpu-amdhsa-m0"><span class="std std-ref">M0</span></a>).</p>
<p>To convert between a segment address and a flat address the base address of the
appertures address can be used. For GFX7-GFX8 these are available in the
<a class="reference internal" href="#amdgpu-amdhsa-hsa-aql-queue"><span class="std std-ref">HSA AQL Queue</span></a> the address of which can be obtained with
Queue Ptr SGPR (see <a class="reference internal" href="#amdgpu-amdhsa-initial-kernel-execution-state"><span class="std std-ref">Initial Kernel Execution State</span></a>). For
GFX9-GFX10 the appature base addresses are directly available as inline constant
registers <code class="docutils literal notranslate"><span class="pre">SRC_SHARED_BASE/LIMIT</span></code> and <code class="docutils literal notranslate"><span class="pre">SRC_PRIVATE_BASE/LIMIT</span></code>. In 64 bit
address mode the apperture sizes are 2^32 bytes and the base is aligned to 2^32
which makes it easier to convert from flat to segment or segment to flat.</p>
</div>
<div class="section" id="image-and-samplers">
<h4><a class="toc-backref" href="#id77">Image and Samplers</a><a class="headerlink" href="#image-and-samplers" title="Permalink to this headline">¶</a></h4>
<p>Image and sample handles created by the ROCm runtime are 64 bit addresses of a
hardware 32 byte V# and 48 byte S# object respectively. In order to support the
HSA <code class="docutils literal notranslate"><span class="pre">query_sampler</span></code> operations two extra dwords are used to store the HSA BRIG
enumeration values for the queries that are not trivially deducible from the S#
representation.</p>
</div>
<div class="section" id="hsa-signals">
<h4><a class="toc-backref" href="#id78">HSA Signals</a><a class="headerlink" href="#hsa-signals" title="Permalink to this headline">¶</a></h4>
<p>HSA signal handles created by the ROCm runtime are 64 bit addresses of a
structure allocated in memory accessible from both the CPU and GPU. The
structure is defined by the ROCm runtime and subject to change between releases
(see <a class="reference internal" href="#amd-rocm-github" id="id33"><span>[AMD-ROCm-github]</span></a>).</p>
</div>
<div class="section" id="hsa-aql-queue">
<span id="amdgpu-amdhsa-hsa-aql-queue"></span><h4><a class="toc-backref" href="#id79">HSA AQL Queue</a><a class="headerlink" href="#hsa-aql-queue" title="Permalink to this headline">¶</a></h4>
<p>The HSA AQL queue structure is defined by the ROCm runtime and subject to change
between releases (see <a class="reference internal" href="#amd-rocm-github" id="id34"><span>[AMD-ROCm-github]</span></a>). For some processors it contains
fields needed to implement certain language features such as the flat address
aperture bases. It also contains fields used by CP such as managing the
allocation of scratch memory.</p>
</div>
<div class="section" id="kernel-descriptor">
<span id="amdgpu-amdhsa-kernel-descriptor"></span><h4><a class="toc-backref" href="#id80">Kernel Descriptor</a><a class="headerlink" href="#kernel-descriptor" title="Permalink to this headline">¶</a></h4>
<p>A kernel descriptor consists of the information needed by CP to initiate the
execution of a kernel, including the entry point address of the machine code
that implements the kernel.</p>
<div class="section" id="kernel-descriptor-for-gfx6-gfx10">
<h5><a class="toc-backref" href="#id81">Kernel Descriptor for GFX6-GFX10</a><a class="headerlink" href="#kernel-descriptor-for-gfx6-gfx10" title="Permalink to this headline">¶</a></h5>
<p>CP microcode requires the Kernel descriptor to be allocated on 64 byte
alignment.</p>
<blockquote>
<div><table class="docutils align-default" id="amdgpu-amdhsa-kernel-descriptor-gfx6-gfx10-table">
<caption><span class="caption-text">Kernel Descriptor for GFX6-GFX10</span><a class="headerlink" href="#amdgpu-amdhsa-kernel-descriptor-gfx6-gfx10-table" title="Permalink to this table">¶</a></caption>
<colgroup>
<col style="width: 7%" />
<col style="width: 7%" />
<col style="width: 31%" />
<col style="width: 55%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>Bits</p></th>
<th class="head"><p>Size</p></th>
<th class="head"><p>Field Name</p></th>
<th class="head"><p>Description</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>31:0</p></td>
<td><p>4 bytes</p></td>
<td><p>GROUP_SEGMENT_FIXED_SIZE</p></td>
<td><p>The amount of fixed local
address space memory
required for a work-group
in bytes. This does not
include any dynamically
allocated local address
space memory that may be
added when the kernel is
dispatched.</p></td>
</tr>
<tr class="row-odd"><td><p>63:32</p></td>
<td><p>4 bytes</p></td>
<td><p>PRIVATE_SEGMENT_FIXED_SIZE</p></td>
<td><p>The amount of fixed
private address space
memory required for a
work-item in bytes. If
is_dynamic_callstack is 1
then additional space must
be added to this value for
the call stack.</p></td>
</tr>
<tr class="row-even"><td><p>127:64</p></td>
<td><p>8 bytes</p></td>
<td></td>
<td><p>Reserved, must be 0.</p></td>
</tr>
<tr class="row-odd"><td><p>191:128</p></td>
<td><p>8 bytes</p></td>
<td><p>KERNEL_CODE_ENTRY_BYTE_OFFSET</p></td>
<td><p>Byte offset (possibly
negative) from base
address of kernel
descriptor to kernel’s
entry point instruction
which must be 256 byte
aligned.</p></td>
</tr>
<tr class="row-even"><td><p>351:272</p></td>
<td><p>20
bytes</p></td>
<td></td>
<td><p>Reserved, must be 0.</p></td>
</tr>
<tr class="row-odd"><td><p>383:352</p></td>
<td><p>4 bytes</p></td>
<td><p>COMPUTE_PGM_RSRC3</p></td>
<td><dl class="simple">
<dt>GFX6-9</dt><dd><p>Reserved, must be 0.</p>
</dd>
<dt>GFX10</dt><dd><p>Compute Shader (CS)
program settings used by
CP to set up
<code class="docutils literal notranslate"><span class="pre">COMPUTE_PGM_RSRC3</span></code>
configuration
register. See
<a class="reference internal" href="#amdgpu-amdhsa-compute-pgm-rsrc3-gfx10-table"><span class="std std-ref">compute_pgm_rsrc3 for GFX10</span></a>.</p>
</dd>
</dl>
</td>
</tr>
<tr class="row-even"><td><p>415:384</p></td>
<td><p>4 bytes</p></td>
<td><p>COMPUTE_PGM_RSRC1</p></td>
<td><p>Compute Shader (CS)
program settings used by
CP to set up
<code class="docutils literal notranslate"><span class="pre">COMPUTE_PGM_RSRC1</span></code>
configuration
register. See
<a class="reference internal" href="#amdgpu-amdhsa-compute-pgm-rsrc1-gfx6-gfx10-table"><span class="std std-ref">compute_pgm_rsrc1 for GFX6-GFX10</span></a>.</p></td>
</tr>
<tr class="row-odd"><td><p>447:416</p></td>
<td><p>4 bytes</p></td>
<td><p>COMPUTE_PGM_RSRC2</p></td>
<td><p>Compute Shader (CS)
program settings used by
CP to set up
<code class="docutils literal notranslate"><span class="pre">COMPUTE_PGM_RSRC2</span></code>
configuration
register. See
<a class="reference internal" href="#amdgpu-amdhsa-compute-pgm-rsrc2-gfx6-gfx10-table"><span class="std std-ref">compute_pgm_rsrc2 for GFX6-GFX10</span></a>.</p></td>
</tr>
<tr class="row-even"><td><p>448</p></td>
<td><p>1 bit</p></td>
<td><p>ENABLE_SGPR_PRIVATE_SEGMENT
_BUFFER</p></td>
<td><p>Enable the setup of the
SGPR user data registers
(see
<a class="reference internal" href="#amdgpu-amdhsa-initial-kernel-execution-state"><span class="std std-ref">Initial Kernel Execution State</span></a>).</p>
<p>The total number of SGPR
user data registers
requested must not exceed
16 and match value in
<code class="docutils literal notranslate"><span class="pre">compute_pgm_rsrc2.user_sgpr.user_sgpr_count</span></code>.
Any requests beyond 16
will be ignored.</p>
</td>
</tr>
<tr class="row-odd"><td><p>449</p></td>
<td><p>1 bit</p></td>
<td><p>ENABLE_SGPR_DISPATCH_PTR</p></td>
<td><p><em>see above</em></p></td>
</tr>
<tr class="row-even"><td><p>450</p></td>
<td><p>1 bit</p></td>
<td><p>ENABLE_SGPR_QUEUE_PTR</p></td>
<td><p><em>see above</em></p></td>
</tr>
<tr class="row-odd"><td><p>451</p></td>
<td><p>1 bit</p></td>
<td><p>ENABLE_SGPR_KERNARG_SEGMENT_PTR</p></td>
<td><p><em>see above</em></p></td>
</tr>
<tr class="row-even"><td><p>452</p></td>
<td><p>1 bit</p></td>
<td><p>ENABLE_SGPR_DISPATCH_ID</p></td>
<td><p><em>see above</em></p></td>
</tr>
<tr class="row-odd"><td><p>453</p></td>
<td><p>1 bit</p></td>
<td><p>ENABLE_SGPR_FLAT_SCRATCH_INIT</p></td>
<td><p><em>see above</em></p></td>
</tr>
<tr class="row-even"><td><p>454</p></td>
<td><p>1 bit</p></td>
<td><p>ENABLE_SGPR_PRIVATE_SEGMENT
_SIZE</p></td>
<td><p><em>see above</em></p></td>
</tr>
<tr class="row-odd"><td><p>457:455</p></td>
<td><p>3 bits</p></td>
<td></td>
<td><p>Reserved, must be 0.</p></td>
</tr>
<tr class="row-even"><td><p>458</p></td>
<td><p>1 bit</p></td>
<td><p>ENABLE_WAVEFRONT_SIZE32</p></td>
<td><dl class="simple">
<dt>GFX6-9</dt><dd><p>Reserved, must be 0.</p>
</dd>
<dt>GFX10</dt><dd><ul class="simple">
<li><p>If 0 execute in
wavefront size 64 mode.</p></li>
<li><p>If 1 execute in
native wavefront size
32 mode.</p></li>
</ul>
</dd>
</dl>
</td>
</tr>
<tr class="row-odd"><td><p>463:459</p></td>
<td><p>5 bits</p></td>
<td></td>
<td><p>Reserved, must be 0.</p></td>
</tr>
<tr class="row-even"><td><p>511:464</p></td>
<td><p>6 bytes</p></td>
<td></td>
<td><p>Reserved, must be 0.</p></td>
</tr>
<tr class="row-odd"><td><p>512</p></td>
<td colspan="3"><p><strong>Total size 64 bytes.</strong></p></td>
</tr>
</tbody>
</table>
</div></blockquote>
<blockquote>
<div><table class="docutils align-default" id="amdgpu-amdhsa-compute-pgm-rsrc1-gfx6-gfx10-table">
<caption><span class="caption-text">compute_pgm_rsrc1 for GFX6-GFX10</span><a class="headerlink" href="#amdgpu-amdhsa-compute-pgm-rsrc1-gfx6-gfx10-table" title="Permalink to this table">¶</a></caption>
<colgroup>
<col style="width: 6%" />
<col style="width: 6%" />
<col style="width: 26%" />
<col style="width: 63%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>Bits</p></th>
<th class="head"><p>Size</p></th>
<th class="head"><p>Field Name</p></th>
<th class="head"><p>Description</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>5:0</p></td>
<td><p>6 bits</p></td>
<td><p>GRANULATED_WORKITEM_VGPR_COUNT</p></td>
<td><p>Number of vector register
blocks used by each work-item;
granularity is device
specific:</p>
<dl class="simple">
<dt>GFX6-GFX9</dt><dd><ul class="simple">
<li><p>vgprs_used 0..256</p></li>
<li><p>max(0, ceil(vgprs_used / 4) - 1)</p></li>
</ul>
</dd>
<dt>GFX10 (wavefront size 64)</dt><dd><ul class="simple">
<li><p>max_vgpr 1..256</p></li>
<li><p>max(0, ceil(vgprs_used / 4) - 1)</p></li>
</ul>
</dd>
<dt>GFX10 (wavefront size 32)</dt><dd><ul class="simple">
<li><p>max_vgpr 1..256</p></li>
<li><p>max(0, ceil(vgprs_used / 8) - 1)</p></li>
</ul>
</dd>
</dl>
<p>Where vgprs_used is defined
as the highest VGPR number
explicitly referenced plus
one.</p>
<p>Used by CP to set up
<code class="docutils literal notranslate"><span class="pre">COMPUTE_PGM_RSRC1.VGPRS</span></code>.</p>
<p>The
<a class="reference internal" href="#amdgpu-assembler"><span class="std std-ref">Assembler</span></a>
calculates this
automatically for the
selected processor from
values provided to the
<cite>.amdhsa_kernel</cite> directive
by the
<cite>.amdhsa_next_free_vgpr</cite>
nested directive (see
<a class="reference internal" href="#amdhsa-kernel-directives-table"><span class="std std-ref">AMDHSA Kernel Assembler Directives</span></a>).</p>
</td>
</tr>
<tr class="row-odd"><td><p>9:6</p></td>
<td><p>4 bits</p></td>
<td><p>GRANULATED_WAVEFRONT_SGPR_COUNT</p></td>
<td><p>Number of scalar register
blocks used by a wavefront;
granularity is device
specific:</p>
<dl class="simple">
<dt>GFX6-GFX8</dt><dd><ul class="simple">
<li><p>sgprs_used 0..112</p></li>
<li><p>max(0, ceil(sgprs_used / 8) - 1)</p></li>
</ul>
</dd>
<dt>GFX9</dt><dd><ul class="simple">
<li><p>sgprs_used 0..112</p></li>
<li><p>2 * max(0, ceil(sgprs_used / 16) - 1)</p></li>
</ul>
</dd>
<dt>GFX10</dt><dd><p>Reserved, must be 0.
(128 SGPRs always
allocated.)</p>
</dd>
</dl>
<p>Where sgprs_used is
defined as the highest
SGPR number explicitly
referenced plus one, plus
a target-specific number
of additional special
SGPRs for VCC,
FLAT_SCRATCH (GFX7+) and
XNACK_MASK (GFX8+), and
any additional
target-specific
limitations. It does not
include the 16 SGPRs added
if a trap handler is
enabled.</p>
<p>The target-specific
limitations and special
SGPR layout are defined in
the hardware
documentation, which can
be found in the
<a class="reference internal" href="#amdgpu-processors"><span class="std std-ref">Processors</span></a>
table.</p>
<p>Used by CP to set up
<code class="docutils literal notranslate"><span class="pre">COMPUTE_PGM_RSRC1.SGPRS</span></code>.</p>
<p>The
<a class="reference internal" href="#amdgpu-assembler"><span class="std std-ref">Assembler</span></a>
calculates this
automatically for the
selected processor from
values provided to the
<cite>.amdhsa_kernel</cite> directive
by the
<cite>.amdhsa_next_free_sgpr</cite>
and <cite>.amdhsa_reserve_*</cite>
nested directives (see
<a class="reference internal" href="#amdhsa-kernel-directives-table"><span class="std std-ref">AMDHSA Kernel Assembler Directives</span></a>).</p>
</td>
</tr>
<tr class="row-even"><td><p>11:10</p></td>
<td><p>2 bits</p></td>
<td><p>PRIORITY</p></td>
<td><p>Must be 0.</p>
<p>Start executing wavefront
at the specified priority.</p>
<p>CP is responsible for
filling in
<code class="docutils literal notranslate"><span class="pre">COMPUTE_PGM_RSRC1.PRIORITY</span></code>.</p>
</td>
</tr>
<tr class="row-odd"><td><p>13:12</p></td>
<td><p>2 bits</p></td>
<td><p>FLOAT_ROUND_MODE_32</p></td>
<td><p>Wavefront starts execution
with specified rounding
mode for single (32
bit) floating point
precision floating point
operations.</p>
<p>Floating point rounding
mode values are defined in
<a class="reference internal" href="#amdgpu-amdhsa-floating-point-rounding-mode-enumeration-values-table"><span class="std std-ref">Floating Point Rounding Mode Enumeration Values</span></a>.</p>
<p>Used by CP to set up
<code class="docutils literal notranslate"><span class="pre">COMPUTE_PGM_RSRC1.FLOAT_MODE</span></code>.</p>
</td>
</tr>
<tr class="row-even"><td><p>15:14</p></td>
<td><p>2 bits</p></td>
<td><p>FLOAT_ROUND_MODE_16_64</p></td>
<td><p>Wavefront starts execution
with specified rounding
denorm mode for half/double (16
and 64 bit) floating point
precision floating point
operations.</p>
<p>Floating point rounding
mode values are defined in
<a class="reference internal" href="#amdgpu-amdhsa-floating-point-rounding-mode-enumeration-values-table"><span class="std std-ref">Floating Point Rounding Mode Enumeration Values</span></a>.</p>
<p>Used by CP to set up
<code class="docutils literal notranslate"><span class="pre">COMPUTE_PGM_RSRC1.FLOAT_MODE</span></code>.</p>
</td>
</tr>
<tr class="row-odd"><td><p>17:16</p></td>
<td><p>2 bits</p></td>
<td><p>FLOAT_DENORM_MODE_32</p></td>
<td><p>Wavefront starts execution
with specified denorm mode
for single (32
bit)  floating point
precision floating point
operations.</p>
<p>Floating point denorm mode
values are defined in
<a class="reference internal" href="#amdgpu-amdhsa-floating-point-denorm-mode-enumeration-values-table"><span class="std std-ref">Floating Point Denorm Mode Enumeration Values</span></a>.</p>
<p>Used by CP to set up
<code class="docutils literal notranslate"><span class="pre">COMPUTE_PGM_RSRC1.FLOAT_MODE</span></code>.</p>
</td>
</tr>
<tr class="row-even"><td><p>19:18</p></td>
<td><p>2 bits</p></td>
<td><p>FLOAT_DENORM_MODE_16_64</p></td>
<td><p>Wavefront starts execution
with specified denorm mode
for half/double (16
and 64 bit) floating point
precision floating point
operations.</p>
<p>Floating point denorm mode
values are defined in
<a class="reference internal" href="#amdgpu-amdhsa-floating-point-denorm-mode-enumeration-values-table"><span class="std std-ref">Floating Point Denorm Mode Enumeration Values</span></a>.</p>
<p>Used by CP to set up
<code class="docutils literal notranslate"><span class="pre">COMPUTE_PGM_RSRC1.FLOAT_MODE</span></code>.</p>
</td>
</tr>
<tr class="row-odd"><td><p>20</p></td>
<td><p>1 bit</p></td>
<td><p>PRIV</p></td>
<td><p>Must be 0.</p>
<p>Start executing wavefront
in privilege trap handler
mode.</p>
<p>CP is responsible for
filling in
<code class="docutils literal notranslate"><span class="pre">COMPUTE_PGM_RSRC1.PRIV</span></code>.</p>
</td>
</tr>
<tr class="row-even"><td><p>21</p></td>
<td><p>1 bit</p></td>
<td><p>ENABLE_DX10_CLAMP</p></td>
<td><p>Wavefront starts execution
with DX10 clamp mode
enabled. Used by the vector
ALU to force DX10 style
treatment of NaN’s (when
set, clamp NaN to zero,
otherwise pass NaN
through).</p>
<p>Used by CP to set up
<code class="docutils literal notranslate"><span class="pre">COMPUTE_PGM_RSRC1.DX10_CLAMP</span></code>.</p>
</td>
</tr>
<tr class="row-odd"><td><p>22</p></td>
<td><p>1 bit</p></td>
<td><p>DEBUG_MODE</p></td>
<td><p>Must be 0.</p>
<p>Start executing wavefront
in single step mode.</p>
<p>CP is responsible for
filling in
<code class="docutils literal notranslate"><span class="pre">COMPUTE_PGM_RSRC1.DEBUG_MODE</span></code>.</p>
</td>
</tr>
<tr class="row-even"><td><p>23</p></td>
<td><p>1 bit</p></td>
<td><p>ENABLE_IEEE_MODE</p></td>
<td><p>Wavefront starts execution
with IEEE mode
enabled. Floating point
opcodes that support
exception flag gathering
will quiet and propagate
signaling-NaN inputs per
IEEE 754-2008. Min_dx10 and
max_dx10 become IEEE
754-2008 compliant due to
signaling-NaN propagation
and quieting.</p>
<p>Used by CP to set up
<code class="docutils literal notranslate"><span class="pre">COMPUTE_PGM_RSRC1.IEEE_MODE</span></code>.</p>
</td>
</tr>
<tr class="row-odd"><td><p>24</p></td>
<td><p>1 bit</p></td>
<td><p>BULKY</p></td>
<td><p>Must be 0.</p>
<p>Only one work-group allowed
to execute on a compute
unit.</p>
<p>CP is responsible for
filling in
<code class="docutils literal notranslate"><span class="pre">COMPUTE_PGM_RSRC1.BULKY</span></code>.</p>
</td>
</tr>
<tr class="row-even"><td><p>25</p></td>
<td><p>1 bit</p></td>
<td><p>CDBG_USER</p></td>
<td><p>Must be 0.</p>
<p>Flag that can be used to
control debugging code.</p>
<p>CP is responsible for
filling in
<code class="docutils literal notranslate"><span class="pre">COMPUTE_PGM_RSRC1.CDBG_USER</span></code>.</p>
</td>
</tr>
<tr class="row-odd"><td><p>26</p></td>
<td><p>1 bit</p></td>
<td><p>FP16_OVFL</p></td>
<td><dl>
<dt>GFX6-GFX8</dt><dd><p>Reserved, must be 0.</p>
</dd>
<dt>GFX9-GFX10</dt><dd><p>Wavefront starts execution
with specified fp16 overflow
mode.</p>
<ul class="simple">
<li><p>If 0, fp16 overflow generates
+/-INF values.</p></li>
<li><p>If 1, fp16 overflow that is the
result of an +/-INF input value
or divide by 0 produces a +/-INF,
otherwise clamps computed
overflow to +/-MAX_FP16 as
appropriate.</p></li>
</ul>
<p>Used by CP to set up
<code class="docutils literal notranslate"><span class="pre">COMPUTE_PGM_RSRC1.FP16_OVFL</span></code>.</p>
</dd>
</dl>
</td>
</tr>
<tr class="row-even"><td><p>28:27</p></td>
<td><p>2 bits</p></td>
<td></td>
<td><p>Reserved, must be 0.</p></td>
</tr>
<tr class="row-odd"><td><p>29</p></td>
<td><p>1 bit</p></td>
<td><p>WGP_MODE</p></td>
<td><dl>
<dt>GFX6-GFX9</dt><dd><p>Reserved, must be 0.</p>
</dd>
<dt>GFX10</dt><dd><ul class="simple">
<li><p>If 0 execute work-groups in
CU wavefront execution mode.</p></li>
<li><p>If 1 execute work-groups on
in WGP wavefront execution mode.</p></li>
</ul>
<p>See <a class="reference internal" href="#amdgpu-amdhsa-memory-model"><span class="std std-ref">Memory Model</span></a>.</p>
<p>Used by CP to set up
<code class="docutils literal notranslate"><span class="pre">COMPUTE_PGM_RSRC1.WGP_MODE</span></code>.</p>
</dd>
</dl>
</td>
</tr>
<tr class="row-even"><td><p>30</p></td>
<td><p>1 bit</p></td>
<td><p>MEM_ORDERED</p></td>
<td><dl>
<dt>GFX6-9</dt><dd><p>Reserved, must be 0.</p>
</dd>
<dt>GFX10</dt><dd><p>Controls the behavior of the
waitcnt’s vmcnt and vscnt
counters.</p>
<ul class="simple">
<li><p>If 0 vmcnt reports completion
of load and atomic with return
out of order with sample
instructions, and the vscnt
reports the completion of
store and atomic without
return in order.</p></li>
<li><p>If 1 vmcnt reports completion
of load, atomic with return
and sample instructions in
order, and the vscnt reports
the completion of store and
atomic without return in order.</p></li>
</ul>
<p>Used by CP to set up
<code class="docutils literal notranslate"><span class="pre">COMPUTE_PGM_RSRC1.MEM_ORDERED</span></code>.</p>
</dd>
</dl>
</td>
</tr>
<tr class="row-odd"><td><p>31</p></td>
<td><p>1 bit</p></td>
<td><p>FWD_PROGRESS</p></td>
<td><dl>
<dt>GFX6-9</dt><dd><p>Reserved, must be 0.</p>
</dd>
<dt>GFX10</dt><dd><ul class="simple">
<li><p>If 0 execute SIMD wavefronts
using oldest first policy.</p></li>
<li><p>If 1 execute SIMD wavefronts to
ensure wavefronts will make some
forward progress.</p></li>
</ul>
<p>Used by CP to set up
<code class="docutils literal notranslate"><span class="pre">COMPUTE_PGM_RSRC1.FWD_PROGRESS</span></code>.</p>
</dd>
</dl>
</td>
</tr>
<tr class="row-even"><td><p>32</p></td>
<td colspan="3"><p><strong>Total size 4 bytes</strong></p></td>
</tr>
</tbody>
</table>
</div></blockquote>
<blockquote>
<div><table class="docutils align-default" id="amdgpu-amdhsa-compute-pgm-rsrc2-gfx6-gfx10-table">
<caption><span class="caption-text">compute_pgm_rsrc2 for GFX6-GFX10</span><a class="headerlink" href="#amdgpu-amdhsa-compute-pgm-rsrc2-gfx6-gfx10-table" title="Permalink to this table">¶</a></caption>
<colgroup>
<col style="width: 6%" />
<col style="width: 6%" />
<col style="width: 26%" />
<col style="width: 63%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>Bits</p></th>
<th class="head"><p>Size</p></th>
<th class="head"><p>Field Name</p></th>
<th class="head"><p>Description</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>0</p></td>
<td><p>1 bit</p></td>
<td><p>ENABLE_SGPR_PRIVATE_SEGMENT
_WAVEFRONT_OFFSET</p></td>
<td><p>Enable the setup of the
SGPR wavefront scratch offset
system register (see
<a class="reference internal" href="#amdgpu-amdhsa-initial-kernel-execution-state"><span class="std std-ref">Initial Kernel Execution State</span></a>).</p>
<p>Used by CP to set up
<code class="docutils literal notranslate"><span class="pre">COMPUTE_PGM_RSRC2.SCRATCH_EN</span></code>.</p>
</td>
</tr>
<tr class="row-odd"><td><p>5:1</p></td>
<td><p>5 bits</p></td>
<td><p>USER_SGPR_COUNT</p></td>
<td><p>The total number of SGPR
user data registers
requested. This number must
match the number of user
data registers enabled.</p>
<p>Used by CP to set up
<code class="docutils literal notranslate"><span class="pre">COMPUTE_PGM_RSRC2.USER_SGPR</span></code>.</p>
</td>
</tr>
<tr class="row-even"><td><p>6</p></td>
<td><p>1 bit</p></td>
<td><p>ENABLE_TRAP_HANDLER</p></td>
<td><p>Must be 0.</p>
<p>This bit represents
<code class="docutils literal notranslate"><span class="pre">COMPUTE_PGM_RSRC2.TRAP_PRESENT</span></code>,
which is set by the CP if
the runtime has installed a
trap handler.</p>
</td>
</tr>
<tr class="row-odd"><td><p>7</p></td>
<td><p>1 bit</p></td>
<td><p>ENABLE_SGPR_WORKGROUP_ID_X</p></td>
<td><p>Enable the setup of the
system SGPR register for
the work-group id in the X
dimension (see
<a class="reference internal" href="#amdgpu-amdhsa-initial-kernel-execution-state"><span class="std std-ref">Initial Kernel Execution State</span></a>).</p>
<p>Used by CP to set up
<code class="docutils literal notranslate"><span class="pre">COMPUTE_PGM_RSRC2.TGID_X_EN</span></code>.</p>
</td>
</tr>
<tr class="row-even"><td><p>8</p></td>
<td><p>1 bit</p></td>
<td><p>ENABLE_SGPR_WORKGROUP_ID_Y</p></td>
<td><p>Enable the setup of the
system SGPR register for
the work-group id in the Y
dimension (see
<a class="reference internal" href="#amdgpu-amdhsa-initial-kernel-execution-state"><span class="std std-ref">Initial Kernel Execution State</span></a>).</p>
<p>Used by CP to set up
<code class="docutils literal notranslate"><span class="pre">COMPUTE_PGM_RSRC2.TGID_Y_EN</span></code>.</p>
</td>
</tr>
<tr class="row-odd"><td><p>9</p></td>
<td><p>1 bit</p></td>
<td><p>ENABLE_SGPR_WORKGROUP_ID_Z</p></td>
<td><p>Enable the setup of the
system SGPR register for
the work-group id in the Z
dimension (see
<a class="reference internal" href="#amdgpu-amdhsa-initial-kernel-execution-state"><span class="std std-ref">Initial Kernel Execution State</span></a>).</p>
<p>Used by CP to set up
<code class="docutils literal notranslate"><span class="pre">COMPUTE_PGM_RSRC2.TGID_Z_EN</span></code>.</p>
</td>
</tr>
<tr class="row-even"><td><p>10</p></td>
<td><p>1 bit</p></td>
<td><p>ENABLE_SGPR_WORKGROUP_INFO</p></td>
<td><p>Enable the setup of the
system SGPR register for
work-group information (see
<a class="reference internal" href="#amdgpu-amdhsa-initial-kernel-execution-state"><span class="std std-ref">Initial Kernel Execution State</span></a>).</p>
<p>Used by CP to set up
<code class="docutils literal notranslate"><span class="pre">COMPUTE_PGM_RSRC2.TGID_SIZE_EN</span></code>.</p>
</td>
</tr>
<tr class="row-odd"><td><p>12:11</p></td>
<td><p>2 bits</p></td>
<td><p>ENABLE_VGPR_WORKITEM_ID</p></td>
<td><p>Enable the setup of the
VGPR system registers used
for the work-item ID.
<a class="reference internal" href="#amdgpu-amdhsa-system-vgpr-work-item-id-enumeration-values-table"><span class="std std-ref">System VGPR Work-Item ID Enumeration Values</span></a>
defines the values.</p>
<p>Used by CP to set up
<code class="docutils literal notranslate"><span class="pre">COMPUTE_PGM_RSRC2.TIDIG_CMP_CNT</span></code>.</p>
</td>
</tr>
<tr class="row-even"><td><p>13</p></td>
<td><p>1 bit</p></td>
<td><p>ENABLE_EXCEPTION_ADDRESS_WATCH</p></td>
<td><p>Must be 0.</p>
<p>Wavefront starts execution
with address watch
exceptions enabled which
are generated when L1 has
witnessed a thread access
an <em>address of
interest</em>.</p>
<p>CP is responsible for
filling in the address
watch bit in
<code class="docutils literal notranslate"><span class="pre">COMPUTE_PGM_RSRC2.EXCP_EN_MSB</span></code>
according to what the
runtime requests.</p>
</td>
</tr>
<tr class="row-odd"><td><p>14</p></td>
<td><p>1 bit</p></td>
<td><p>ENABLE_EXCEPTION_MEMORY</p></td>
<td><p>Must be 0.</p>
<p>Wavefront starts execution
with memory violation
exceptions exceptions
enabled which are generated
when a memory violation has
occurred for this wavefront from
L1 or LDS
(write-to-read-only-memory,
mis-aligned atomic, LDS
address out of range,
illegal address, etc.).</p>
<p>CP sets the memory
violation bit in
<code class="docutils literal notranslate"><span class="pre">COMPUTE_PGM_RSRC2.EXCP_EN_MSB</span></code>
according to what the
runtime requests.</p>
</td>
</tr>
<tr class="row-even"><td><p>23:15</p></td>
<td><p>9 bits</p></td>
<td><p>GRANULATED_LDS_SIZE</p></td>
<td><p>Must be 0.</p>
<p>CP uses the rounded value
from the dispatch packet,
not this value, as the
dispatch may contain
dynamically allocated group
segment memory. CP writes
directly to
<code class="docutils literal notranslate"><span class="pre">COMPUTE_PGM_RSRC2.LDS_SIZE</span></code>.</p>
<p>Amount of group segment
(LDS) to allocate for each
work-group. Granularity is
device specific:</p>
<dl class="simple">
<dt>GFX6:</dt><dd><p>roundup(lds-size / (64 * 4))</p>
</dd>
<dt>GFX7-GFX10:</dt><dd><p>roundup(lds-size / (128 * 4))</p>
</dd>
</dl>
</td>
</tr>
<tr class="row-odd"><td><p>24</p></td>
<td><p>1 bit</p></td>
<td><p>ENABLE_EXCEPTION_IEEE_754_FP
_INVALID_OPERATION</p></td>
<td><p>Wavefront starts execution
with specified exceptions
enabled.</p>
<p>Used by CP to set up
<code class="docutils literal notranslate"><span class="pre">COMPUTE_PGM_RSRC2.EXCP_EN</span></code>
(set from bits 0..6).</p>
<p>IEEE 754 FP Invalid
Operation</p>
</td>
</tr>
<tr class="row-even"><td><p>25</p></td>
<td><p>1 bit</p></td>
<td><p>ENABLE_EXCEPTION_FP_DENORMAL
_SOURCE</p></td>
<td><p>FP Denormal one or more
input operands is a
denormal number</p></td>
</tr>
<tr class="row-odd"><td><p>26</p></td>
<td><p>1 bit</p></td>
<td><p>ENABLE_EXCEPTION_IEEE_754_FP
_DIVISION_BY_ZERO</p></td>
<td><p>IEEE 754 FP Division by
Zero</p></td>
</tr>
<tr class="row-even"><td><p>27</p></td>
<td><p>1 bit</p></td>
<td><p>ENABLE_EXCEPTION_IEEE_754_FP
_OVERFLOW</p></td>
<td><p>IEEE 754 FP FP Overflow</p></td>
</tr>
<tr class="row-odd"><td><p>28</p></td>
<td><p>1 bit</p></td>
<td><p>ENABLE_EXCEPTION_IEEE_754_FP
_UNDERFLOW</p></td>
<td><p>IEEE 754 FP Underflow</p></td>
</tr>
<tr class="row-even"><td><p>29</p></td>
<td><p>1 bit</p></td>
<td><p>ENABLE_EXCEPTION_IEEE_754_FP
_INEXACT</p></td>
<td><p>IEEE 754 FP Inexact</p></td>
</tr>
<tr class="row-odd"><td><p>30</p></td>
<td><p>1 bit</p></td>
<td><p>ENABLE_EXCEPTION_INT_DIVIDE_BY
_ZERO</p></td>
<td><p>Integer Division by Zero
(rcp_iflag_f32 instruction
only)</p></td>
</tr>
<tr class="row-even"><td><p>31</p></td>
<td><p>1 bit</p></td>
<td></td>
<td><p>Reserved, must be 0.</p></td>
</tr>
<tr class="row-odd"><td><p>32</p></td>
<td colspan="3"><p><strong>Total size 4 bytes.</strong></p></td>
</tr>
</tbody>
</table>
</div></blockquote>
<blockquote>
<div><table class="docutils align-default" id="amdgpu-amdhsa-compute-pgm-rsrc3-gfx10-table">
<caption><span class="caption-text">compute_pgm_rsrc3 for GFX10</span><a class="headerlink" href="#amdgpu-amdhsa-compute-pgm-rsrc3-gfx10-table" title="Permalink to this table">¶</a></caption>
<colgroup>
<col style="width: 6%" />
<col style="width: 6%" />
<col style="width: 26%" />
<col style="width: 63%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>Bits</p></th>
<th class="head"><p>Size</p></th>
<th class="head"><p>Field Name</p></th>
<th class="head"><p>Description</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>3:0</p></td>
<td><p>4 bits</p></td>
<td><p>SHARED_VGPR_COUNT</p></td>
<td><p>Number of shared VGPRs for wavefront size 64. Granularity 8. Value 0-120.
compute_pgm_rsrc1.vgprs + shared_vgpr_cnt cannot exceed 64.</p></td>
</tr>
<tr class="row-odd"><td><p>31:4</p></td>
<td><p>28
bits</p></td>
<td></td>
<td><p>Reserved, must be 0.</p></td>
</tr>
<tr class="row-even"><td><p>32</p></td>
<td colspan="3"><p><strong>Total size 4 bytes.</strong></p></td>
</tr>
</tbody>
</table>
</div></blockquote>
<blockquote>
<div><table class="docutils align-default" id="amdgpu-amdhsa-floating-point-rounding-mode-enumeration-values-table">
<caption><span class="caption-text">Floating Point Rounding Mode Enumeration Values</span><a class="headerlink" href="#amdgpu-amdhsa-floating-point-rounding-mode-enumeration-values-table" title="Permalink to this table">¶</a></caption>
<colgroup>
<col style="width: 52%" />
<col style="width: 7%" />
<col style="width: 41%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>Enumeration Name</p></th>
<th class="head"><p>Value</p></th>
<th class="head"><p>Description</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>FLOAT_ROUND_MODE_NEAR_EVEN</p></td>
<td><p>0</p></td>
<td><p>Round Ties To Even</p></td>
</tr>
<tr class="row-odd"><td><p>FLOAT_ROUND_MODE_PLUS_INFINITY</p></td>
<td><p>1</p></td>
<td><p>Round Toward +infinity</p></td>
</tr>
<tr class="row-even"><td><p>FLOAT_ROUND_MODE_MINUS_INFINITY</p></td>
<td><p>2</p></td>
<td><p>Round Toward -infinity</p></td>
</tr>
<tr class="row-odd"><td><p>FLOAT_ROUND_MODE_ZERO</p></td>
<td><p>3</p></td>
<td><p>Round Toward 0</p></td>
</tr>
</tbody>
</table>
</div></blockquote>
<blockquote>
<div><table class="docutils align-default" id="amdgpu-amdhsa-floating-point-denorm-mode-enumeration-values-table">
<caption><span class="caption-text">Floating Point Denorm Mode Enumeration Values</span><a class="headerlink" href="#amdgpu-amdhsa-floating-point-denorm-mode-enumeration-values-table" title="Permalink to this table">¶</a></caption>
<colgroup>
<col style="width: 52%" />
<col style="width: 7%" />
<col style="width: 41%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>Enumeration Name</p></th>
<th class="head"><p>Value</p></th>
<th class="head"><p>Description</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>FLOAT_DENORM_MODE_FLUSH_SRC_DST</p></td>
<td><p>0</p></td>
<td><p>Flush Source and Destination
Denorms</p></td>
</tr>
<tr class="row-odd"><td><p>FLOAT_DENORM_MODE_FLUSH_DST</p></td>
<td><p>1</p></td>
<td><p>Flush Output Denorms</p></td>
</tr>
<tr class="row-even"><td><p>FLOAT_DENORM_MODE_FLUSH_SRC</p></td>
<td><p>2</p></td>
<td><p>Flush Source Denorms</p></td>
</tr>
<tr class="row-odd"><td><p>FLOAT_DENORM_MODE_FLUSH_NONE</p></td>
<td><p>3</p></td>
<td><p>No Flush</p></td>
</tr>
</tbody>
</table>
</div></blockquote>
<blockquote>
<div><table class="docutils align-default" id="amdgpu-amdhsa-system-vgpr-work-item-id-enumeration-values-table">
<caption><span class="caption-text">System VGPR Work-Item ID Enumeration Values</span><a class="headerlink" href="#amdgpu-amdhsa-system-vgpr-work-item-id-enumeration-values-table" title="Permalink to this table">¶</a></caption>
<colgroup>
<col style="width: 55%" />
<col style="width: 7%" />
<col style="width: 38%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>Enumeration Name</p></th>
<th class="head"><p>Value</p></th>
<th class="head"><p>Description</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>SYSTEM_VGPR_WORKITEM_ID_X</p></td>
<td><p>0</p></td>
<td><p>Set work-item X dimension
ID.</p></td>
</tr>
<tr class="row-odd"><td><p>SYSTEM_VGPR_WORKITEM_ID_X_Y</p></td>
<td><p>1</p></td>
<td><p>Set work-item X and Y
dimensions ID.</p></td>
</tr>
<tr class="row-even"><td><p>SYSTEM_VGPR_WORKITEM_ID_X_Y_Z</p></td>
<td><p>2</p></td>
<td><p>Set work-item X, Y and Z
dimensions ID.</p></td>
</tr>
<tr class="row-odd"><td><p>SYSTEM_VGPR_WORKITEM_ID_UNDEFINED</p></td>
<td><p>3</p></td>
<td><p>Undefined.</p></td>
</tr>
</tbody>
</table>
</div></blockquote>
</div>
</div>
<div class="section" id="initial-kernel-execution-state">
<span id="amdgpu-amdhsa-initial-kernel-execution-state"></span><h4><a class="toc-backref" href="#id82">Initial Kernel Execution State</a><a class="headerlink" href="#initial-kernel-execution-state" title="Permalink to this headline">¶</a></h4>
<p>This section defines the register state that will be set up by the packet
processor prior to the start of execution of every wavefront. This is limited by
the constraints of the hardware controllers of CP/ADC/SPI.</p>
<p>The order of the SGPR registers is defined, but the compiler can specify which
ones are actually setup in the kernel descriptor using the <code class="docutils literal notranslate"><span class="pre">enable_sgpr_*</span></code> bit
fields (see <a class="reference internal" href="#amdgpu-amdhsa-kernel-descriptor"><span class="std std-ref">Kernel Descriptor</span></a>). The register numbers used
for enabled registers are dense starting at SGPR0: the first enabled register is
SGPR0, the next enabled register is SGPR1 etc.; disabled registers do not have
an SGPR number.</p>
<p>The initial SGPRs comprise up to 16 User SRGPs that are set by CP and apply to
all wavefronts of the grid. It is possible to specify more than 16 User SGPRs using
the <code class="docutils literal notranslate"><span class="pre">enable_sgpr_*</span></code> bit fields, in which case only the first 16 are actually
initialized. These are then immediately followed by the System SGPRs that are
set up by ADC/SPI and can have different values for each wavefront of the grid
dispatch.</p>
<p>SGPR register initial state is defined in
<a class="reference internal" href="#amdgpu-amdhsa-sgpr-register-set-up-order-table"><span class="std std-ref">SGPR Register Set Up Order</span></a>.</p>
<blockquote>
<div><table class="docutils align-default" id="amdgpu-amdhsa-sgpr-register-set-up-order-table">
<caption><span class="caption-text">SGPR Register Set Up Order</span><a class="headerlink" href="#amdgpu-amdhsa-sgpr-register-set-up-order-table" title="Permalink to this table">¶</a></caption>
<colgroup>
<col style="width: 13%" />
<col style="width: 33%" />
<col style="width: 8%" />
<col style="width: 46%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>SGPR Order</p></th>
<th class="head"><p>Name
(kernel descriptor enable
field)</p></th>
<th class="head"><p>Number
of
SGPRs</p></th>
<th class="head"><p>Description</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>First</p></td>
<td><p>Private Segment Buffer
(enable_sgpr_private
_segment_buffer)</p></td>
<td><p>4</p></td>
<td><p>V# that can be used, together
with Scratch Wavefront Offset
as an offset, to access the
private memory space using a
segment address.</p>
<p>CP uses the value provided by
the runtime.</p>
</td>
</tr>
<tr class="row-odd"><td><p>then</p></td>
<td><p>Dispatch Ptr
(enable_sgpr_dispatch_ptr)</p></td>
<td><p>2</p></td>
<td><p>64 bit address of AQL dispatch
packet for kernel dispatch
actually executing.</p></td>
</tr>
<tr class="row-even"><td><p>then</p></td>
<td><p>Queue Ptr
(enable_sgpr_queue_ptr)</p></td>
<td><p>2</p></td>
<td><p>64 bit address of amd_queue_t
object for AQL queue on which
the dispatch packet was
queued.</p></td>
</tr>
<tr class="row-odd"><td><p>then</p></td>
<td><p>Kernarg Segment Ptr
(enable_sgpr_kernarg
_segment_ptr)</p></td>
<td><p>2</p></td>
<td><p>64 bit address of Kernarg
segment. This is directly
copied from the
kernarg_address in the kernel
dispatch packet.</p>
<p>Having CP load it once avoids
loading it at the beginning of
every wavefront.</p>
</td>
</tr>
<tr class="row-even"><td><p>then</p></td>
<td><p>Dispatch Id
(enable_sgpr_dispatch_id)</p></td>
<td><p>2</p></td>
<td><p>64 bit Dispatch ID of the
dispatch packet being
executed.</p></td>
</tr>
<tr class="row-odd"><td><p>then</p></td>
<td><p>Flat Scratch Init
(enable_sgpr_flat_scratch
_init)</p></td>
<td><p>2</p></td>
<td><p>This is 2 SGPRs:</p>
<dl>
<dt>GFX6</dt><dd><p>Not supported.</p>
</dd>
<dt>GFX7-GFX8</dt><dd><p>The first SGPR is a 32 bit
byte offset from
<code class="docutils literal notranslate"><span class="pre">SH_HIDDEN_PRIVATE_BASE_VIMID</span></code>
to per SPI base of memory
for scratch for the queue
executing the kernel
dispatch. CP obtains this
from the runtime. (The
Scratch Segment Buffer base
address is
<code class="docutils literal notranslate"><span class="pre">SH_HIDDEN_PRIVATE_BASE_VIMID</span></code>
plus this offset.) The value
of Scratch Wavefront Offset must
be added to this offset by
the kernel machine code,
right shifted by 8, and
moved to the FLAT_SCRATCH_HI
SGPR register.
FLAT_SCRATCH_HI corresponds
to SGPRn-4 on GFX7, and
SGPRn-6 on GFX8 (where SGPRn
is the highest numbered SGPR
allocated to the wavefront).
FLAT_SCRATCH_HI is
multiplied by 256 (as it is
in units of 256 bytes) and
added to
<code class="docutils literal notranslate"><span class="pre">SH_HIDDEN_PRIVATE_BASE_VIMID</span></code>
to calculate the per wavefront
FLAT SCRATCH BASE in flat
memory instructions that
access the scratch
apperture.</p>
<p>The second SGPR is 32 bit
byte size of a single
work-item’s scratch memory
usage. CP obtains this from
the runtime, and it is
always a multiple of DWORD.
CP checks that the value in
the kernel dispatch packet
Private Segment Byte Size is
not larger, and requests the
runtime to increase the
queue’s scratch size if
necessary. The kernel code
must move it to
FLAT_SCRATCH_LO which is
SGPRn-3 on GFX7 and SGPRn-5
on GFX8. FLAT_SCRATCH_LO is
used as the FLAT SCRATCH
SIZE in flat memory
instructions. Having CP load
it once avoids loading it at
the beginning of every
wavefront.</p>
</dd>
<dt>GFX9-GFX10</dt><dd><p>This is the
64 bit base address of the
per SPI scratch backing
memory managed by SPI for
the queue executing the
kernel dispatch. CP obtains
this from the runtime (and
divides it if there are
multiple Shader Arrays each
with its own SPI). The value
of Scratch Wavefront Offset must
be added by the kernel
machine code and the result
moved to the FLAT_SCRATCH
SGPR which is SGPRn-6 and
SGPRn-5. It is used as the
FLAT SCRATCH BASE in flat
memory instructions.</p>
</dd>
</dl>
</td>
</tr>
<tr class="row-even"><td><p>then</p></td>
<td><p>Private Segment Size</p></td>
<td><p>1</p></td>
<td><p>The 32 bit byte size of a
(enable_sgpr_private single
work-item’s
scratch_segment_size) memory
allocation. This is the
value from the kernel
dispatch packet Private
Segment Byte Size rounded up
by CP to a multiple of
DWORD.</p>
<p>Having CP load it once avoids
loading it at the beginning of
every wavefront.</p>
<p>This is not used for
GFX7-GFX8 since it is the same
value as the second SGPR of
Flat Scratch Init. However, it
may be needed for GFX9-GFX10 which
changes the meaning of the
Flat Scratch Init value.</p>
</td>
</tr>
<tr class="row-odd"><td><p>then</p></td>
<td><p>Grid Work-Group Count X
(enable_sgpr_grid
_workgroup_count_X)</p></td>
<td><p>1</p></td>
<td><p>32 bit count of the number of
work-groups in the X dimension
for the grid being
executed. Computed from the
fields in the kernel dispatch
packet as ((grid_size.x +
workgroup_size.x - 1) /
workgroup_size.x).</p></td>
</tr>
<tr class="row-even"><td><p>then</p></td>
<td><p>Grid Work-Group Count Y
(enable_sgpr_grid
_workgroup_count_Y &amp;&amp;
less than 16 previous
SGPRs)</p></td>
<td><p>1</p></td>
<td><p>32 bit count of the number of
work-groups in the Y dimension
for the grid being
executed. Computed from the
fields in the kernel dispatch
packet as ((grid_size.y +
workgroup_size.y - 1) /
workgroupSize.y).</p>
<p>Only initialized if &lt;16
previous SGPRs initialized.</p>
</td>
</tr>
<tr class="row-odd"><td><p>then</p></td>
<td><p>Grid Work-Group Count Z
(enable_sgpr_grid
_workgroup_count_Z &amp;&amp;
less than 16 previous
SGPRs)</p></td>
<td><p>1</p></td>
<td><p>32 bit count of the number of
work-groups in the Z dimension
for the grid being
executed. Computed from the
fields in the kernel dispatch
packet as ((grid_size.z +
workgroup_size.z - 1) /
workgroupSize.z).</p>
<p>Only initialized if &lt;16
previous SGPRs initialized.</p>
</td>
</tr>
<tr class="row-even"><td><p>then</p></td>
<td><p>Work-Group Id X
(enable_sgpr_workgroup_id
_X)</p></td>
<td><p>1</p></td>
<td><p>32 bit work-group id in X
dimension of grid for
wavefront.</p></td>
</tr>
<tr class="row-odd"><td><p>then</p></td>
<td><p>Work-Group Id Y
(enable_sgpr_workgroup_id
_Y)</p></td>
<td><p>1</p></td>
<td><p>32 bit work-group id in Y
dimension of grid for
wavefront.</p></td>
</tr>
<tr class="row-even"><td><p>then</p></td>
<td><p>Work-Group Id Z
(enable_sgpr_workgroup_id
_Z)</p></td>
<td><p>1</p></td>
<td><p>32 bit work-group id in Z
dimension of grid for
wavefront.</p></td>
</tr>
<tr class="row-odd"><td><p>then</p></td>
<td><p>Work-Group Info
(enable_sgpr_workgroup
_info)</p></td>
<td><p>1</p></td>
<td><p>{first_wavefront, 14’b0000,
ordered_append_term[10:0],
threadgroup_size_in_wavefronts[5:0]}</p></td>
</tr>
<tr class="row-even"><td><p>then</p></td>
<td><p>Scratch Wavefront Offset
(enable_sgpr_private
_segment_wavefront_offset)</p></td>
<td><p>1</p></td>
<td><p>32 bit byte offset from base
of scratch base of queue
executing the kernel
dispatch. Must be used as an
offset with Private
segment address when using
Scratch Segment Buffer. It
must be used to set up FLAT
SCRATCH for flat addressing
(see
<a class="reference internal" href="#amdgpu-amdhsa-flat-scratch"><span class="std std-ref">Flat Scratch</span></a>).</p></td>
</tr>
</tbody>
</table>
</div></blockquote>
<p>The order of the VGPR registers is defined, but the compiler can specify which
ones are actually setup in the kernel descriptor using the <code class="docutils literal notranslate"><span class="pre">enable_vgpr*</span></code> bit
fields (see <a class="reference internal" href="#amdgpu-amdhsa-kernel-descriptor"><span class="std std-ref">Kernel Descriptor</span></a>). The register numbers used
for enabled registers are dense starting at VGPR0: the first enabled register is
VGPR0, the next enabled register is VGPR1 etc.; disabled registers do not have a
VGPR number.</p>
<p>VGPR register initial state is defined in
<a class="reference internal" href="#amdgpu-amdhsa-vgpr-register-set-up-order-table"><span class="std std-ref">VGPR Register Set Up Order</span></a>.</p>
<blockquote>
<div><table class="docutils align-default" id="amdgpu-amdhsa-vgpr-register-set-up-order-table">
<caption><span class="caption-text">VGPR Register Set Up Order</span><a class="headerlink" href="#amdgpu-amdhsa-vgpr-register-set-up-order-table" title="Permalink to this table">¶</a></caption>
<colgroup>
<col style="width: 14%" />
<col style="width: 36%" />
<col style="width: 8%" />
<col style="width: 42%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>VGPR Order</p></th>
<th class="head"><p>Name
(kernel descriptor enable
field)</p></th>
<th class="head"><p>Number
of
VGPRs</p></th>
<th class="head"><p>Description</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>First</p></td>
<td><p>Work-Item Id X
(Always initialized)</p></td>
<td><p>1</p></td>
<td><p>32 bit work item id in X
dimension of work-group for
wavefront lane.</p></td>
</tr>
<tr class="row-odd"><td><p>then</p></td>
<td><p>Work-Item Id Y
(enable_vgpr_workitem_id
&gt; 0)</p></td>
<td><p>1</p></td>
<td><p>32 bit work item id in Y
dimension of work-group for
wavefront lane.</p></td>
</tr>
<tr class="row-even"><td><p>then</p></td>
<td><p>Work-Item Id Z
(enable_vgpr_workitem_id
&gt; 1)</p></td>
<td><p>1</p></td>
<td><p>32 bit work item id in Z
dimension of work-group for
wavefront lane.</p></td>
</tr>
</tbody>
</table>
</div></blockquote>
<p>The setting of registers is done by GPU CP/ADC/SPI hardware as follows:</p>
<ol class="arabic simple">
<li><p>SGPRs before the Work-Group Ids are set by CP using the 16 User Data
registers.</p></li>
<li><p>Work-group Id registers X, Y, Z are set by ADC which supports any
combination including none.</p></li>
<li><p>Scratch Wavefront Offset is set by SPI in a per wavefront basis which is why
its value cannot included with the flat scratch init value which is per queue.</p></li>
<li><p>The VGPRs are set by SPI which only supports specifying either (X), (X, Y)
or (X, Y, Z).</p></li>
</ol>
<p>Flat Scratch register pair are adjacent SGRRs so they can be moved as a 64 bit
value to the hardware required SGPRn-3 and SGPRn-4 respectively.</p>
<p>The global segment can be accessed either using buffer instructions (GFX6 which
has V# 64 bit address support), flat instructions (GFX7-GFX10), or global
instructions (GFX9-GFX10).</p>
<p>If buffer operations are used then the compiler can generate a V# with the
following properties:</p>
<ul class="simple">
<li><p>base address of 0</p></li>
<li><p>no swizzle</p></li>
<li><p>ATC: 1 if IOMMU present (such as APU)</p></li>
<li><p>ptr64: 1</p></li>
<li><p>MTYPE set to support memory coherence that matches the runtime (such as CC for
APU and NC for dGPU).</p></li>
</ul>
</div>
<div class="section" id="kernel-prolog">
<span id="amdgpu-amdhsa-kernel-prolog"></span><h4><a class="toc-backref" href="#id83">Kernel Prolog</a><a class="headerlink" href="#kernel-prolog" title="Permalink to this headline">¶</a></h4>
<div class="section" id="m0">
<span id="amdgpu-amdhsa-m0"></span><h5><a class="toc-backref" href="#id84">M0</a><a class="headerlink" href="#m0" title="Permalink to this headline">¶</a></h5>
<dl class="simple">
<dt>GFX6-GFX8</dt><dd><p>The M0 register must be initialized with a value at least the total LDS size
if the kernel may access LDS via DS or flat operations. Total LDS size is
available in dispatch packet. For M0, it is also possible to use maximum
possible value of LDS for given target (0x7FFF for GFX6 and 0xFFFF for
GFX7-GFX8).</p>
</dd>
<dt>GFX9-GFX10</dt><dd><p>The M0 register is not used for range checking LDS accesses and so does not
need to be initialized in the prolog.</p>
</dd>
</dl>
</div>
<div class="section" id="flat-scratch">
<span id="amdgpu-amdhsa-flat-scratch"></span><h5><a class="toc-backref" href="#id85">Flat Scratch</a><a class="headerlink" href="#flat-scratch" title="Permalink to this headline">¶</a></h5>
<p>If the kernel may use flat operations to access scratch memory, the prolog code
must set up FLAT_SCRATCH register pair (FLAT_SCRATCH_LO/FLAT_SCRATCH_HI which
are in SGPRn-4/SGPRn-3). Initialization uses Flat Scratch Init and Scratch Wavefront
Offset SGPR registers (see <a class="reference internal" href="#amdgpu-amdhsa-initial-kernel-execution-state"><span class="std std-ref">Initial Kernel Execution State</span></a>):</p>
<dl class="simple">
<dt>GFX6</dt><dd><p>Flat scratch is not supported.</p>
</dd>
<dt>GFX7-GFX8</dt><dd><ol class="arabic simple">
<li><p>The low word of Flat Scratch Init is 32 bit byte offset from
<code class="docutils literal notranslate"><span class="pre">SH_HIDDEN_PRIVATE_BASE_VIMID</span></code> to the base of scratch backing memory
being managed by SPI for the queue executing the kernel dispatch. This is
the same value used in the Scratch Segment Buffer V# base address. The
prolog must add the value of Scratch Wavefront Offset to get the wavefront’s byte
scratch backing memory offset from <code class="docutils literal notranslate"><span class="pre">SH_HIDDEN_PRIVATE_BASE_VIMID</span></code>. Since
FLAT_SCRATCH_LO is in units of 256 bytes, the offset must be right shifted
by 8 before moving into FLAT_SCRATCH_LO.</p></li>
<li><p>The second word of Flat Scratch Init is 32 bit byte size of a single
work-items scratch memory usage. This is directly loaded from the kernel
dispatch packet Private Segment Byte Size and rounded up to a multiple of
DWORD. Having CP load it once avoids loading it at the beginning of every
wavefront. The prolog must move it to FLAT_SCRATCH_LO for use as FLAT SCRATCH
SIZE.</p></li>
</ol>
</dd>
<dt>GFX9-GFX10</dt><dd><p>The Flat Scratch Init is the 64 bit address of the base of scratch backing
memory being managed by SPI for the queue executing the kernel dispatch. The
prolog must add the value of Scratch Wavefront Offset and moved to the FLAT_SCRATCH
pair for use as the flat scratch base in flat memory instructions.</p>
</dd>
</dl>
</div>
</div>
<div class="section" id="memory-model">
<span id="amdgpu-amdhsa-memory-model"></span><h4><a class="toc-backref" href="#id86">Memory Model</a><a class="headerlink" href="#memory-model" title="Permalink to this headline">¶</a></h4>
<p>This section describes the mapping of LLVM memory model onto AMDGPU machine code
(see <a class="reference internal" href="LangRef.html#memmodel"><span class="std std-ref">Memory Model for Concurrent Operations</span></a>). <em>The implementation is WIP.</em></p>
<p>The AMDGPU backend supports the memory synchronization scopes specified in
<a class="reference internal" href="#amdgpu-memory-scopes"><span class="std std-ref">Memory Scopes</span></a>.</p>
<p>The code sequences used to implement the memory model are defined in table
<a class="reference internal" href="#amdgpu-amdhsa-memory-model-code-sequences-gfx6-gfx10-table"><span class="std std-ref">AMDHSA Memory Model Code Sequences GFX6-GFX10</span></a>.</p>
<p>The sequences specify the order of instructions that a single thread must
execute. The <code class="docutils literal notranslate"><span class="pre">s_waitcnt</span></code> and <code class="docutils literal notranslate"><span class="pre">buffer_wbinvl1_vol</span></code> are defined with respect
to other memory instructions executed by the same thread. This allows them to be
moved earlier or later which can allow them to be combined with other instances
of the same instruction, or hoisted/sunk out of loops to improve
performance. Only the instructions related to the memory model are given;
additional <code class="docutils literal notranslate"><span class="pre">s_waitcnt</span></code> instructions are required to ensure registers are
defined before being used. These may be able to be combined with the memory
model <code class="docutils literal notranslate"><span class="pre">s_waitcnt</span></code> instructions as described above.</p>
<p>The AMDGPU backend supports the following memory models:</p>
<blockquote>
<div><dl class="simple">
<dt>HSA Memory Model <a class="reference internal" href="#hsa" id="id35"><span>[HSA]</span></a></dt><dd><p>The HSA memory model uses a single happens-before relation for all address
spaces (see <a class="reference internal" href="#amdgpu-address-spaces"><span class="std std-ref">Address Spaces</span></a>).</p>
</dd>
<dt>OpenCL Memory Model <a class="reference internal" href="#id47" id="id36"><span>[OpenCL]</span></a></dt><dd><p>The OpenCL memory model which has separate happens-before relations for the
global and local address spaces. Only a fence specifying both global and
local address space, and seq_cst instructions join the relationships. Since
the LLVM <code class="docutils literal notranslate"><span class="pre">memfence</span></code> instruction does not allow an address space to be
specified the OpenCL fence has to convervatively assume both local and
global address space was specified. However, optimizations can often be
done to eliminate the additional <code class="docutils literal notranslate"><span class="pre">s_waitcnt</span></code> instructions when there are
no intervening memory instructions which access the corresponding address
space. The code sequences in the table indicate what can be omitted for the
OpenCL memory. The target triple environment is used to determine if the
source language is OpenCL (see <a class="reference internal" href="#amdgpu-opencl"><span class="std std-ref">OpenCL</span></a>).</p>
</dd>
</dl>
</div></blockquote>
<p><code class="docutils literal notranslate"><span class="pre">ds/flat_load/store/atomic</span></code> instructions to local memory are termed LDS
operations.</p>
<p><code class="docutils literal notranslate"><span class="pre">buffer/global/flat_load/store/atomic</span></code> instructions to global memory are
termed vector memory operations.</p>
<p>For GFX6-GFX9:</p>
<ul class="simple">
<li><p>Each agent has multiple shader arrays (SA).</p></li>
<li><p>Each SA has multiple compute units (CU).</p></li>
<li><p>Each CU has multiple SIMDs that execute wavefronts.</p></li>
<li><p>The wavefronts for a single work-group are executed in the same CU but may be
executed by different SIMDs.</p></li>
<li><p>Each CU has a single LDS memory shared by the wavefronts of the work-groups
executing on it.</p></li>
<li><p>All LDS operations of a CU are performed as wavefront wide operations in a
global order and involve no caching. Completion is reported to a wavefront in
execution order.</p></li>
<li><p>The LDS memory has multiple request queues shared by the SIMDs of a
CU. Therefore, the LDS operations performed by different wavefronts of a work-group
can be reordered relative to each other, which can result in reordering the
visibility of vector memory operations with respect to LDS operations of other
wavefronts in the same work-group. A <code class="docutils literal notranslate"><span class="pre">s_waitcnt</span> <span class="pre">lgkmcnt(0)</span></code> is required to
ensure synchronization between LDS operations and vector memory operations
between wavefronts of a work-group, but not between operations performed by the
same wavefront.</p></li>
<li><p>The vector memory operations are performed as wavefront wide operations and
completion is reported to a wavefront in execution order. The exception is
that for GFX7-GFX9 <code class="docutils literal notranslate"><span class="pre">flat_load/store/atomic</span></code> instructions can report out of
vector memory order if they access LDS memory, and out of LDS operation order
if they access global memory.</p></li>
<li><p>The vector memory operations access a single vector L1 cache shared by all
SIMDs a CU. Therefore, no special action is required for coherence between the
lanes of a single wavefront, or for coherence between wavefronts in the same
work-group. A <code class="docutils literal notranslate"><span class="pre">buffer_wbinvl1_vol</span></code> is required for coherence between wavefronts
executing in different work-groups as they may be executing on different CUs.</p></li>
<li><p>The scalar memory operations access a scalar L1 cache shared by all wavefronts
on a group of CUs. The scalar and vector L1 caches are not coherent. However,
scalar operations are used in a restricted way so do not impact the memory
model. See <a class="reference internal" href="#amdgpu-amdhsa-memory-spaces"><span class="std std-ref">Memory Spaces</span></a>.</p></li>
<li><p>The vector and scalar memory operations use an L2 cache shared by all CUs on
the same agent.</p></li>
<li><p>The L2 cache has independent channels to service disjoint ranges of virtual
addresses.</p></li>
<li><p>Each CU has a separate request queue per channel. Therefore, the vector and
scalar memory operations performed by wavefronts executing in different work-groups
(which may be executing on different CUs) of an agent can be reordered
relative to each other. A <code class="docutils literal notranslate"><span class="pre">s_waitcnt</span> <span class="pre">vmcnt(0)</span></code> is required to ensure
synchronization between vector memory operations of different CUs. It ensures a
previous vector memory operation has completed before executing a subsequent
vector memory or LDS operation and so can be used to meet the requirements of
acquire and release.</p></li>
<li><p>The L2 cache can be kept coherent with other agents on some targets, or ranges
of virtual addresses can be set up to bypass it to ensure system coherence.</p></li>
</ul>
<p>For GFX10:</p>
<ul class="simple">
<li><p>Each agent has multiple shader arrays (SA).</p></li>
<li><p>Each SA has multiple work-group processors (WGP).</p></li>
<li><p>Each WGP has multiple compute units (CU).</p></li>
<li><p>Each CU has multiple SIMDs that execute wavefronts.</p></li>
<li><p>The wavefronts for a single work-group are executed in the same
WGP. In CU wavefront execution mode the wavefronts may be executed by
different SIMDs in the same CU. In WGP wavefront execution mode the
wavefronts may be executed by different SIMDs in different CUs in the same
WGP.</p></li>
<li><p>Each WGP has a single LDS memory shared by the wavefronts of the work-groups
executing on it.</p></li>
<li><p>All LDS operations of a WGP are performed as wavefront wide operations in a
global order and involve no caching. Completion is reported to a wavefront in
execution order.</p></li>
<li><p>The LDS memory has multiple request queues shared by the SIMDs of a
WGP. Therefore, the LDS operations performed by different wavefronts of a work-group
can be reordered relative to each other, which can result in reordering the
visibility of vector memory operations with respect to LDS operations of other
wavefronts in the same work-group. A <code class="docutils literal notranslate"><span class="pre">s_waitcnt</span> <span class="pre">lgkmcnt(0)</span></code> is required to
ensure synchronization between LDS operations and vector memory operations
between wavefronts of a work-group, but not between operations performed by the
same wavefront.</p></li>
<li><p>The vector memory operations are performed as wavefront wide operations.
Completion of load/store/sample operations are reported to a wavefront in
execution order of other load/store/sample operations performed by that
wavefront.</p></li>
<li><p>The vector memory operations access a vector L0 cache. There is a single L0
cache per CU. Each SIMD of a CU accesses the same L0 cache.
Therefore, no special action is required for coherence between the lanes of a
single wavefront. However, a <code class="docutils literal notranslate"><span class="pre">BUFFER_GL0_INV</span></code> is required for coherence
between wavefronts executing in the same work-group as they may be executing on
SIMDs of different CUs that access different L0s. A <code class="docutils literal notranslate"><span class="pre">BUFFER_GL0_INV</span></code> is also
required for coherence between wavefronts executing in different work-groups as
they may be executing on different WGPs.</p></li>
<li><p>The scalar memory operations access a scalar L0 cache shared by all wavefronts
on a WGP. The scalar and vector L0 caches are not coherent. However, scalar
operations are used in a restricted way so do not impact the memory model. See
<a class="reference internal" href="#amdgpu-amdhsa-memory-spaces"><span class="std std-ref">Memory Spaces</span></a>.</p></li>
<li><p>The vector and scalar memory L0 caches use an L1 cache shared by all WGPs on
the same SA. Therefore, no special action is required for coherence between
the wavefronts of a single work-group. However, a <code class="docutils literal notranslate"><span class="pre">BUFFER_GL1_INV</span></code> is
required for coherence between wavefronts executing in different work-groups as
they may be executing on different SAs that access different L1s.</p></li>
<li><p>The L1 caches have independent quadrants to service disjoint ranges of virtual
addresses.</p></li>
<li><p>Each L0 cache has a separate request queue per L1 quadrant. Therefore, the
vector and scalar memory operations performed by different wavefronts, whether
executing in the same or different work-groups (which may be executing on
different CUs accessing different L0s), can be reordered relative to each
other. A <code class="docutils literal notranslate"><span class="pre">s_waitcnt</span> <span class="pre">vmcnt(0)</span> <span class="pre">&amp;</span> <span class="pre">vscnt(0)</span></code> is required to ensure synchronization
between vector memory operations of different wavefronts. It ensures a previous
vector memory operation has completed before executing a subsequent vector
memory or LDS operation and so can be used to meet the requirements of acquire,
release and sequential consistency.</p></li>
<li><p>The L1 caches use an L2 cache shared by all SAs on the same agent.</p></li>
<li><p>The L2 cache has independent channels to service disjoint ranges of virtual
addresses.</p></li>
<li><p>Each L1 quadrant of a single SA accesses a different L2 channel. Each L1
quadrant has a separate request queue per L2 channel. Therefore, the vector
and scalar memory operations performed by wavefronts executing in different
work-groups (which may be executing on different SAs) of an agent can be
reordered relative to each other. A <code class="docutils literal notranslate"><span class="pre">s_waitcnt</span> <span class="pre">vmcnt(0)</span> <span class="pre">&amp;</span> <span class="pre">vscnt(0)</span></code> is
required to ensure synchronization between vector memory operations of
different SAs. It ensures a previous vector memory operation has completed
before executing a subsequent vector memory and so can be used to meet the
requirements of acquire, release and sequential consistency.</p></li>
<li><p>The L2 cache can be kept coherent with other agents on some targets, or ranges
of virtual addresses can be set up to bypass it to ensure system coherence.</p></li>
</ul>
<p>Private address space uses <code class="docutils literal notranslate"><span class="pre">buffer_load/store</span></code> using the scratch V# (GFX6-GFX8),
or <code class="docutils literal notranslate"><span class="pre">scratch_load/store</span></code> (GFX9-GFX10). Since only a single thread is accessing the
memory, atomic memory orderings are not meaningful and all accesses are treated
as non-atomic.</p>
<p>Constant address space uses <code class="docutils literal notranslate"><span class="pre">buffer/global_load</span></code> instructions (or equivalent
scalar memory instructions). Since the constant address space contents do not
change during the execution of a kernel dispatch it is not legal to perform
stores, and atomic memory orderings are not meaningful and all access are
treated as non-atomic.</p>
<p>A memory synchronization scope wider than work-group is not meaningful for the
group (LDS) address space and is treated as work-group.</p>
<p>The memory model does not support the region address space which is treated as
non-atomic.</p>
<p>Acquire memory ordering is not meaningful on store atomic instructions and is
treated as non-atomic.</p>
<p>Release memory ordering is not meaningful on load atomic instructions and is
treated a non-atomic.</p>
<p>Acquire-release memory ordering is not meaningful on load or store atomic
instructions and is treated as acquire and release respectively.</p>
<p>AMDGPU backend only uses scalar memory operations to access memory that is
proven to not change during the execution of the kernel dispatch. This includes
constant address space and global address space for program scope const
variables. Therefore the kernel machine code does not have to maintain the
scalar L1 cache to ensure it is coherent with the vector L1 cache. The scalar
and vector L1 caches are invalidated between kernel dispatches by CP since
constant address space data may change between kernel dispatch executions. See
<a class="reference internal" href="#amdgpu-amdhsa-memory-spaces"><span class="std std-ref">Memory Spaces</span></a>.</p>
<p>The one execption is if scalar writes are used to spill SGPR registers. In this
case the AMDGPU backend ensures the memory location used to spill is never
accessed by vector memory operations at the same time. If scalar writes are used
then a <code class="docutils literal notranslate"><span class="pre">s_dcache_wb</span></code> is inserted before the <code class="docutils literal notranslate"><span class="pre">s_endpgm</span></code> and before a function
return since the locations may be used for vector memory instructions by a
future wavefront that uses the same scratch area, or a function call that creates a
frame at the same address, respectively. There is no need for a <code class="docutils literal notranslate"><span class="pre">s_dcache_inv</span></code>
as all scalar writes are write-before-read in the same thread.</p>
<p>For GFX6-GFX9, scratch backing memory (which is used for the private address space)
is accessed with MTYPE NC_NV (non-coherenent non-volatile). Since the private
address space is only accessed by a single thread, and is always
write-before-read, there is never a need to invalidate these entries from the L1
cache. Hence all cache invalidates are done as <code class="docutils literal notranslate"><span class="pre">*_vol</span></code> to only invalidate the
volatile cache lines.</p>
<p>For GFX10, scratch backing memory (which is used for the private address space)
is accessed with MTYPE NC (non-coherenent). Since the private address space is
only accessed by a single thread, and is always write-before-read, there is
never a need to invalidate these entries from the L0 or L1 caches.</p>
<p>For GFX10, wavefronts are executed in native mode with in-order reporting of loads
and sample instructions. In this mode vmcnt reports completion of load, atomic
with return and sample instructions in order, and the vscnt reports the
completion of store and atomic without return in order. See <code class="docutils literal notranslate"><span class="pre">MEM_ORDERED</span></code> field
in <a class="reference internal" href="#amdgpu-amdhsa-compute-pgm-rsrc1-gfx6-gfx10-table"><span class="std std-ref">compute_pgm_rsrc1 for GFX6-GFX10</span></a>.</p>
<p>In GFX10, wavefronts can be executed in WGP or CU wavefront execution mode:</p>
<ul class="simple">
<li><p>In WGP wavefront execution mode the wavefronts of a work-group are executed
on the SIMDs of both CUs of the WGP. Therefore, explicit management of the per
CU L0 caches is required for work-group synchronization. Also accesses to L1 at
work-group scope need to be expicitly ordered as the accesses from different
CUs are not ordered.</p></li>
<li><p>In CU wavefront execution mode the wavefronts of a work-group are executed on
the SIMDs of a single CU of the WGP. Therefore, all global memory access by
the work-group access the same L0 which in turn ensures L1 accesses are
ordered and so do not require explicit management of the caches for
work-group synchronization.</p></li>
</ul>
<p>See <code class="docutils literal notranslate"><span class="pre">WGP_MODE</span></code> field in <a class="reference internal" href="#amdgpu-amdhsa-compute-pgm-rsrc1-gfx6-gfx10-table"><span class="std std-ref">compute_pgm_rsrc1 for GFX6-GFX10</span></a>
and <a class="reference internal" href="#amdgpu-target-features"><span class="std std-ref">Target Features</span></a>.</p>
<p>On dGPU the kernarg backing memory is accessed as UC (uncached) to avoid needing
to invalidate the L2 cache. For GFX6-GFX9, this also causes it to be treated as
non-volatile and so is not invalidated by <code class="docutils literal notranslate"><span class="pre">*_vol</span></code>. On APU it is accessed as CC
(cache coherent) and so the L2 cache will be coherent with the CPU and other
agents.</p>
<blockquote>
<div><table class="docutils align-default" id="amdgpu-amdhsa-memory-model-code-sequences-gfx6-gfx10-table">
<caption><span class="caption-text">AMDHSA Memory Model Code Sequences GFX6-GFX10</span><a class="headerlink" href="#amdgpu-amdhsa-memory-model-code-sequences-gfx6-gfx10-table" title="Permalink to this table">¶</a></caption>
<colgroup>
<col style="width: 9%" />
<col style="width: 9%" />
<col style="width: 11%" />
<col style="width: 8%" />
<col style="width: 24%" />
<col style="width: 39%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>LLVM Instr</p></th>
<th class="head"><p>LLVM Memory
Ordering</p></th>
<th class="head"><p>LLVM Memory
Sync Scope</p></th>
<th class="head"><p>AMDGPU
Address
Space</p></th>
<th class="head"><p>AMDGPU Machine Code
GFX6-9</p></th>
<th class="head"><p>AMDGPU Machine Code
GFX10</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td colspan="6"><p><strong>Non-Atomic</strong></p></td>
</tr>
<tr class="row-odd"><td><p>load</p></td>
<td><p><em>none</em></p></td>
<td><p><em>none</em></p></td>
<td><ul class="simple">
<li><p>global</p></li>
<li><p>generic</p></li>
<li><p>private</p></li>
<li><p>constant</p></li>
</ul>
</td>
<td><ul class="simple">
<li><p>!volatile &amp; !nontemporal</p>
<ol class="arabic simple">
<li><p>buffer/global/flat_load</p></li>
</ol>
</li>
<li><p>volatile &amp; !nontemporal</p>
<ol class="arabic simple">
<li><p>buffer/global/flat_load
glc=1</p></li>
</ol>
</li>
<li><p>nontemporal</p>
<ol class="arabic simple">
<li><p>buffer/global/flat_load
glc=1 slc=1</p></li>
</ol>
</li>
</ul>
</td>
<td><ul class="simple">
<li><p>!volatile &amp; !nontemporal</p>
<ol class="arabic simple">
<li><p>buffer/global/flat_load</p></li>
</ol>
</li>
<li><p>volatile &amp; !nontemporal</p>
<ol class="arabic simple">
<li><p>buffer/global/flat_load
glc=1 dlc=1</p></li>
</ol>
</li>
<li><p>nontemporal</p>
<ol class="arabic simple">
<li><p>buffer/global/flat_load
slc=1</p></li>
</ol>
</li>
</ul>
</td>
</tr>
<tr class="row-even"><td><p>load</p></td>
<td><p><em>none</em></p></td>
<td><p><em>none</em></p></td>
<td><ul class="simple">
<li><p>local</p></li>
</ul>
</td>
<td><ol class="arabic simple">
<li><p>ds_load</p></li>
</ol>
</td>
<td><ol class="arabic simple">
<li><p>ds_load</p></li>
</ol>
</td>
</tr>
<tr class="row-odd"><td><p>store</p></td>
<td><p><em>none</em></p></td>
<td><p><em>none</em></p></td>
<td><ul class="simple">
<li><p>global</p></li>
<li><p>generic</p></li>
<li><p>private</p></li>
<li><p>constant</p></li>
</ul>
</td>
<td><ul class="simple">
<li><p>!nontemporal</p>
<ol class="arabic simple">
<li><p>buffer/global/flat_store</p></li>
</ol>
</li>
<li><p>nontemporal</p>
<ol class="arabic simple">
<li><p>buffer/global/flat_stote
glc=1 slc=1</p></li>
</ol>
</li>
</ul>
</td>
<td><ul>
<li><p>!nontemporal</p>
<ol class="arabic simple">
<li><p>buffer/global/flat_store</p></li>
</ol>
</li>
<li><p>nontemporal</p>
<blockquote>
<div><ol class="arabic simple">
<li><p>buffer/global/flat_store
slc=1</p></li>
</ol>
</div></blockquote>
</li>
</ul>
</td>
</tr>
<tr class="row-even"><td><p>store</p></td>
<td><p><em>none</em></p></td>
<td><p><em>none</em></p></td>
<td><ul class="simple">
<li><p>local</p></li>
</ul>
</td>
<td><ol class="arabic simple">
<li><p>ds_store</p></li>
</ol>
</td>
<td><ol class="arabic simple">
<li><p>ds_store</p></li>
</ol>
</td>
</tr>
<tr class="row-odd"><td colspan="6"><p><strong>Unordered Atomic</strong></p></td>
</tr>
<tr class="row-even"><td><p>load atomic</p></td>
<td><p>unordered</p></td>
<td><p><em>any</em></p></td>
<td><p><em>any</em></p></td>
<td><p><em>Same as non-atomic</em>.</p></td>
<td><p><em>Same as non-atomic</em>.</p></td>
</tr>
<tr class="row-odd"><td><p>store atomic</p></td>
<td><p>unordered</p></td>
<td><p><em>any</em></p></td>
<td><p><em>any</em></p></td>
<td><p><em>Same as non-atomic</em>.</p></td>
<td><p><em>Same as non-atomic</em>.</p></td>
</tr>
<tr class="row-even"><td><p>atomicrmw</p></td>
<td><p>unordered</p></td>
<td><p><em>any</em></p></td>
<td><p><em>any</em></p></td>
<td><p><em>Same as monotonic
atomic</em>.</p></td>
<td><p><em>Same as monotonic
atomic</em>.</p></td>
</tr>
<tr class="row-odd"><td colspan="6"><p><strong>Monotonic Atomic</strong></p></td>
</tr>
<tr class="row-even"><td><p>load atomic</p></td>
<td><p>monotonic</p></td>
<td><ul class="simple">
<li><p>singlethread</p></li>
<li><p>wavefront</p></li>
</ul>
</td>
<td><ul class="simple">
<li><p>global</p></li>
<li><p>generic</p></li>
</ul>
</td>
<td><ol class="arabic simple">
<li><p>buffer/global/flat_load</p></li>
</ol>
</td>
<td><ol class="arabic simple">
<li><p>buffer/global/flat_load</p></li>
</ol>
</td>
</tr>
<tr class="row-odd"><td><p>load atomic</p></td>
<td><p>monotonic</p></td>
<td><ul class="simple">
<li><p>workgroup</p></li>
</ul>
</td>
<td><ul class="simple">
<li><p>global</p></li>
<li><p>generic</p></li>
</ul>
</td>
<td><ol class="arabic simple">
<li><p>buffer/global/flat_load</p></li>
</ol>
</td>
<td><ol class="arabic simple">
<li><p>buffer/global/flat_load
glc=1</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>If CU wavefront execution mode, omit glc=1.</p></li>
</ul>
</div></blockquote>
</td>
</tr>
<tr class="row-even"><td><p>load atomic</p></td>
<td><p>monotonic</p></td>
<td><ul class="simple">
<li><p>singlethread</p></li>
<li><p>wavefront</p></li>
<li><p>workgroup</p></li>
</ul>
</td>
<td><ul class="simple">
<li><p>local</p></li>
</ul>
</td>
<td><ol class="arabic simple">
<li><p>ds_load</p></li>
</ol>
</td>
<td><ol class="arabic simple">
<li><p>ds_load</p></li>
</ol>
</td>
</tr>
<tr class="row-odd"><td><p>load atomic</p></td>
<td><p>monotonic</p></td>
<td><ul class="simple">
<li><p>agent</p></li>
<li><p>system</p></li>
</ul>
</td>
<td><ul class="simple">
<li><p>global</p></li>
<li><p>generic</p></li>
</ul>
</td>
<td><ol class="arabic simple">
<li><p>buffer/global/flat_load
glc=1</p></li>
</ol>
</td>
<td><ol class="arabic simple">
<li><p>buffer/global/flat_load
glc=1 dlc=1</p></li>
</ol>
</td>
</tr>
<tr class="row-even"><td><p>store atomic</p></td>
<td><p>monotonic</p></td>
<td><ul class="simple">
<li><p>singlethread</p></li>
<li><p>wavefront</p></li>
<li><p>workgroup</p></li>
<li><p>agent</p></li>
<li><p>system</p></li>
</ul>
</td>
<td><ul class="simple">
<li><p>global</p></li>
<li><p>generic</p></li>
</ul>
</td>
<td><ol class="arabic simple">
<li><p>buffer/global/flat_store</p></li>
</ol>
</td>
<td><ol class="arabic simple">
<li><p>buffer/global/flat_store</p></li>
</ol>
</td>
</tr>
<tr class="row-odd"><td><p>store atomic</p></td>
<td><p>monotonic</p></td>
<td><ul class="simple">
<li><p>singlethread</p></li>
<li><p>wavefront</p></li>
<li><p>workgroup</p></li>
</ul>
</td>
<td><ul class="simple">
<li><p>local</p></li>
</ul>
</td>
<td><ol class="arabic simple">
<li><p>ds_store</p></li>
</ol>
</td>
<td><ol class="arabic simple">
<li><p>ds_store</p></li>
</ol>
</td>
</tr>
<tr class="row-even"><td><p>atomicrmw</p></td>
<td><p>monotonic</p></td>
<td><ul class="simple">
<li><p>singlethread</p></li>
<li><p>wavefront</p></li>
<li><p>workgroup</p></li>
<li><p>agent</p></li>
<li><p>system</p></li>
</ul>
</td>
<td><ul class="simple">
<li><p>global</p></li>
<li><p>generic</p></li>
</ul>
</td>
<td><ol class="arabic simple">
<li><p>buffer/global/flat_atomic</p></li>
</ol>
</td>
<td><ol class="arabic simple">
<li><p>buffer/global/flat_atomic</p></li>
</ol>
</td>
</tr>
<tr class="row-odd"><td><p>atomicrmw</p></td>
<td><p>monotonic</p></td>
<td><ul class="simple">
<li><p>singlethread</p></li>
<li><p>wavefront</p></li>
<li><p>workgroup</p></li>
</ul>
</td>
<td><ul class="simple">
<li><p>local</p></li>
</ul>
</td>
<td><ol class="arabic simple">
<li><p>ds_atomic</p></li>
</ol>
</td>
<td><ol class="arabic simple">
<li><p>ds_atomic</p></li>
</ol>
</td>
</tr>
<tr class="row-even"><td colspan="6"><p><strong>Acquire Atomic</strong></p></td>
</tr>
<tr class="row-odd"><td><p>load atomic</p></td>
<td><p>acquire</p></td>
<td><ul class="simple">
<li><p>singlethread</p></li>
<li><p>wavefront</p></li>
</ul>
</td>
<td><ul class="simple">
<li><p>global</p></li>
<li><p>local</p></li>
<li><p>generic</p></li>
</ul>
</td>
<td><ol class="arabic simple">
<li><p>buffer/global/ds/flat_load</p></li>
</ol>
</td>
<td><ol class="arabic simple">
<li><p>buffer/global/ds/flat_load</p></li>
</ol>
</td>
</tr>
<tr class="row-even"><td><p>load atomic</p></td>
<td><p>acquire</p></td>
<td><ul class="simple">
<li><p>workgroup</p></li>
</ul>
</td>
<td><ul class="simple">
<li><p>global</p></li>
</ul>
</td>
<td><ol class="arabic simple">
<li><p>buffer/global/flat_load</p></li>
</ol>
</td>
<td><ol class="arabic simple">
<li><p>buffer/global_load glc=1</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>If CU wavefront execution mode, omit glc=1.</p></li>
</ul>
</div></blockquote>
<ol class="arabic simple" start="2">
<li><p>s_waitcnt vmcnt(0)</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>If CU wavefront execution mode, omit.</p></li>
<li><p>Must happen before
the following buffer_gl0_inv
and before any following
global/generic
load/load
atomic/stote/store
atomic/atomicrmw.</p></li>
</ul>
</div></blockquote>
<ol class="arabic simple" start="3">
<li><p>buffer_gl0_inv</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>If CU wavefront execution mode, omit.</p></li>
<li><p>Ensures that
following
loads will not see
stale data.</p></li>
</ul>
</div></blockquote>
</td>
</tr>
<tr class="row-odd"><td><p>load atomic</p></td>
<td><p>acquire</p></td>
<td><ul class="simple">
<li><p>workgroup</p></li>
</ul>
</td>
<td><ul class="simple">
<li><p>local</p></li>
</ul>
</td>
<td><ol class="arabic simple">
<li><p>ds_load</p></li>
<li><p>s_waitcnt lgkmcnt(0)</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>If OpenCL, omit.</p></li>
<li><p>Must happen before
any following
global/generic
load/load
atomic/store/store
atomic/atomicrmw.</p></li>
<li><p>Ensures any
following global
data read is no
older than the load
atomic value being
acquired.</p></li>
</ul>
</div></blockquote>
</td>
<td><ol class="arabic simple">
<li><p>ds_load</p></li>
<li><p>s_waitcnt lgkmcnt(0)</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>If OpenCL, omit.</p></li>
<li><p>Must happen before
the following buffer_gl0_inv
and before any following
global/generic load/load
atomic/store/store
atomic/atomicrmw.</p></li>
<li><p>Ensures any
following global
data read is no
older than the load
atomic value being
acquired.</p></li>
</ul>
</div></blockquote>
<ol class="arabic simple" start="3">
<li><p>buffer_gl0_inv</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>If CU wavefront execution mode, omit.</p></li>
<li><p>If OpenCL, omit.</p></li>
<li><p>Ensures that
following
loads will not see
stale data.</p></li>
</ul>
</div></blockquote>
</td>
</tr>
<tr class="row-even"><td><p>load atomic</p></td>
<td><p>acquire</p></td>
<td><ul class="simple">
<li><p>workgroup</p></li>
</ul>
</td>
<td><ul class="simple">
<li><p>generic</p></li>
</ul>
</td>
<td><ol class="arabic simple">
<li><p>flat_load</p></li>
<li><p>s_waitcnt lgkmcnt(0)</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>If OpenCL, omit.</p></li>
<li><p>Must happen before
any following
global/generic
load/load
atomic/store/store
atomic/atomicrmw.</p></li>
<li><p>Ensures any
following global
data read is no
older than the load
atomic value being
acquired.</p></li>
</ul>
</div></blockquote>
</td>
<td><ol class="arabic simple">
<li><p>flat_load glc=1</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>If CU wavefront execution mode, omit glc=1.</p></li>
</ul>
</div></blockquote>
<ol class="arabic simple" start="2">
<li><p>s_waitcnt lgkmcnt(0) &amp;
vmcnt(0)</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>If CU wavefront execution mode, omit vmcnt.</p></li>
<li><p>If OpenCL, omit
lgkmcnt(0).</p></li>
<li><p>Must happen before
the following
buffer_gl0_inv and any
following global/generic
load/load
atomic/store/store
atomic/atomicrmw.</p></li>
<li><p>Ensures any
following global
data read is no
older than the load
atomic value being
acquired.</p></li>
</ul>
</div></blockquote>
<ol class="arabic simple" start="3">
<li><p>buffer_gl0_inv</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>If CU wavefront execution mode, omit.</p></li>
<li><p>Ensures that
following
loads will not see
stale data.</p></li>
</ul>
</div></blockquote>
</td>
</tr>
<tr class="row-odd"><td><p>load atomic</p></td>
<td><p>acquire</p></td>
<td><ul class="simple">
<li><p>agent</p></li>
<li><p>system</p></li>
</ul>
</td>
<td><ul class="simple">
<li><p>global</p></li>
</ul>
</td>
<td><ol class="arabic simple">
<li><p>buffer/global/flat_load
glc=1</p></li>
<li><p>s_waitcnt vmcnt(0)</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>Must happen before
following
buffer_wbinvl1_vol.</p></li>
<li><p>Ensures the load
has completed
before invalidating
the cache.</p></li>
</ul>
</div></blockquote>
<ol class="arabic simple" start="3">
<li><p>buffer_wbinvl1_vol</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>Must happen before
any following
global/generic
load/load
atomic/atomicrmw.</p></li>
<li><p>Ensures that
following
loads will not see
stale global data.</p></li>
</ul>
</div></blockquote>
</td>
<td><ol class="arabic simple">
<li><p>buffer/global_load
glc=1 dlc=1</p></li>
<li><p>s_waitcnt vmcnt(0)</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>Must happen before
following
buffer_gl*_inv.</p></li>
<li><p>Ensures the load
has completed
before invalidating
the caches.</p></li>
</ul>
</div></blockquote>
<ol class="arabic simple" start="3">
<li><p>buffer_gl0_inv;
buffer_gl1_inv</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>Must happen before
any following
global/generic
load/load
atomic/atomicrmw.</p></li>
<li><p>Ensures that
following
loads will not see
stale global data.</p></li>
</ul>
</div></blockquote>
</td>
</tr>
<tr class="row-even"><td><p>load atomic</p></td>
<td><p>acquire</p></td>
<td><ul class="simple">
<li><p>agent</p></li>
<li><p>system</p></li>
</ul>
</td>
<td><ul class="simple">
<li><p>generic</p></li>
</ul>
</td>
<td><ol class="arabic simple">
<li><p>flat_load glc=1</p></li>
<li><p>s_waitcnt vmcnt(0) &amp;
lgkmcnt(0)</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>If OpenCL omit
lgkmcnt(0).</p></li>
<li><p>Must happen before
following
buffer_wbinvl1_vol.</p></li>
<li><p>Ensures the flat_load
has completed
before invalidating
the cache.</p></li>
</ul>
</div></blockquote>
<ol class="arabic simple" start="3">
<li><p>buffer_wbinvl1_vol</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>Must happen before
any following
global/generic
load/load
atomic/atomicrmw.</p></li>
<li><p>Ensures that
following loads
will not see stale
global data.</p></li>
</ul>
</div></blockquote>
</td>
<td><ol class="arabic simple">
<li><p>flat_load glc=1 dlc=1</p></li>
<li><p>s_waitcnt vmcnt(0) &amp;
lgkmcnt(0)</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>If OpenCL omit
lgkmcnt(0).</p></li>
<li><p>Must happen before
following
buffer_gl*_invl.</p></li>
<li><p>Ensures the flat_load
has completed
before invalidating
the caches.</p></li>
</ul>
</div></blockquote>
<ol class="arabic simple" start="3">
<li><p>buffer_gl0_inv;
buffer_gl1_inv</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>Must happen before
any following
global/generic
load/load
atomic/atomicrmw.</p></li>
<li><p>Ensures that
following loads
will not see stale
global data.</p></li>
</ul>
</div></blockquote>
</td>
</tr>
<tr class="row-odd"><td><p>atomicrmw</p></td>
<td><p>acquire</p></td>
<td><ul class="simple">
<li><p>singlethread</p></li>
<li><p>wavefront</p></li>
</ul>
</td>
<td><ul class="simple">
<li><p>global</p></li>
<li><p>local</p></li>
<li><p>generic</p></li>
</ul>
</td>
<td><ol class="arabic simple">
<li><p>buffer/global/ds/flat_atomic</p></li>
</ol>
</td>
<td><ol class="arabic simple">
<li><p>buffer/global/ds/flat_atomic</p></li>
</ol>
</td>
</tr>
<tr class="row-even"><td><p>atomicrmw</p></td>
<td><p>acquire</p></td>
<td><ul class="simple">
<li><p>workgroup</p></li>
</ul>
</td>
<td><ul class="simple">
<li><p>global</p></li>
</ul>
</td>
<td><ol class="arabic simple">
<li><p>buffer/global/flat_atomic</p></li>
</ol>
</td>
<td><ol class="arabic simple">
<li><p>buffer/global_atomic</p></li>
<li><p>s_waitcnt vm/vscnt(0)</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>If CU wavefront execution mode, omit.</p></li>
<li><p>Use vmcnt if atomic with
return and vscnt if atomic
with no-return.</p></li>
<li><p>Must happen before
the following buffer_gl0_inv
and before any following
global/generic
load/load
atomic/stote/store
atomic/atomicrmw.</p></li>
</ul>
</div></blockquote>
<ol class="arabic simple" start="3">
<li><p>buffer_gl0_inv</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>If CU wavefront execution mode, omit.</p></li>
<li><p>Ensures that
following
loads will not see
stale data.</p></li>
</ul>
</div></blockquote>
</td>
</tr>
<tr class="row-odd"><td><p>atomicrmw</p></td>
<td><p>acquire</p></td>
<td><ul class="simple">
<li><p>workgroup</p></li>
</ul>
</td>
<td><ul class="simple">
<li><p>local</p></li>
</ul>
</td>
<td><ol class="arabic simple">
<li><p>ds_atomic</p></li>
<li><p>waitcnt lgkmcnt(0)</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>If OpenCL, omit.</p></li>
<li><p>Must happen before
any following
global/generic
load/load
atomic/store/store
atomic/atomicrmw.</p></li>
<li><p>Ensures any
following global
data read is no
older than the
atomicrmw value
being acquired.</p></li>
</ul>
</div></blockquote>
</td>
<td><ol class="arabic simple">
<li><p>ds_atomic</p></li>
<li><p>waitcnt lgkmcnt(0)</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>If OpenCL, omit.</p></li>
<li><p>Must happen before
the following
buffer_gl0_inv.</p></li>
<li><p>Ensures any
following global
data read is no
older than the
atomicrmw value
being acquired.</p></li>
</ul>
</div></blockquote>
<ol class="arabic simple" start="3">
<li><p>buffer_gl0_inv</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>If OpenCL omit.</p></li>
<li><p>Ensures that
following
loads will not see
stale data.</p></li>
</ul>
</div></blockquote>
</td>
</tr>
<tr class="row-even"><td><p>atomicrmw</p></td>
<td><p>acquire</p></td>
<td><ul class="simple">
<li><p>workgroup</p></li>
</ul>
</td>
<td><ul class="simple">
<li><p>generic</p></li>
</ul>
</td>
<td><ol class="arabic simple">
<li><p>flat_atomic</p></li>
<li><p>waitcnt lgkmcnt(0)</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>If OpenCL, omit.</p></li>
<li><p>Must happen before
any following
global/generic
load/load
atomic/store/store
atomic/atomicrmw.</p></li>
<li><p>Ensures any
following global
data read is no
older than the
atomicrmw value
being acquired.</p></li>
</ul>
</div></blockquote>
</td>
<td><ol class="arabic simple">
<li><p>flat_atomic</p></li>
<li><p>waitcnt lgkmcnt(0) &amp;
vm/vscnt(0)</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>If CU wavefront execution mode, omit vm/vscnt.</p></li>
<li><p>If OpenCL, omit
waitcnt lgkmcnt(0)..</p></li>
<li><p>Use vmcnt if atomic with
return and vscnt if atomic
with no-return.
waitcnt lgkmcnt(0).</p></li>
<li><p>Must happen before
the following
buffer_gl0_inv.</p></li>
<li><p>Ensures any
following global
data read is no
older than the
atomicrmw value
being acquired.</p></li>
</ul>
</div></blockquote>
<ol class="arabic simple" start="3">
<li><p>buffer_gl0_inv</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>If CU wavefront execution mode, omit.</p></li>
<li><p>Ensures that
following
loads will not see
stale data.</p></li>
</ul>
</div></blockquote>
</td>
</tr>
<tr class="row-odd"><td><p>atomicrmw</p></td>
<td><p>acquire</p></td>
<td><ul class="simple">
<li><p>agent</p></li>
<li><p>system</p></li>
</ul>
</td>
<td><ul class="simple">
<li><p>global</p></li>
</ul>
</td>
<td><ol class="arabic simple">
<li><p>buffer/global/flat_atomic</p></li>
<li><p>s_waitcnt vmcnt(0)</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>Must happen before
following
buffer_wbinvl1_vol.</p></li>
<li><p>Ensures the
atomicrmw has
completed before
invalidating the
cache.</p></li>
</ul>
</div></blockquote>
<ol class="arabic simple" start="3">
<li><p>buffer_wbinvl1_vol</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>Must happen before
any following
global/generic
load/load
atomic/atomicrmw.</p></li>
<li><p>Ensures that
following loads
will not see stale
global data.</p></li>
</ul>
</div></blockquote>
</td>
<td><ol class="arabic simple">
<li><p>buffer/global_atomic</p></li>
<li><p>s_waitcnt vm/vscnt(0)</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>Use vmcnt if atomic with
return and vscnt if atomic
with no-return.
waitcnt lgkmcnt(0).</p></li>
<li><p>Must happen before
following
buffer_gl*_inv.</p></li>
<li><p>Ensures the
atomicrmw has
completed before
invalidating the
caches.</p></li>
</ul>
</div></blockquote>
<ol class="arabic simple" start="3">
<li><p>buffer_gl0_inv;
buffer_gl1_inv</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>Must happen before
any following
global/generic
load/load
atomic/atomicrmw.</p></li>
<li><p>Ensures that
following loads
will not see stale
global data.</p></li>
</ul>
</div></blockquote>
</td>
</tr>
<tr class="row-even"><td><p>atomicrmw</p></td>
<td><p>acquire</p></td>
<td><ul class="simple">
<li><p>agent</p></li>
<li><p>system</p></li>
</ul>
</td>
<td><ul class="simple">
<li><p>generic</p></li>
</ul>
</td>
<td><ol class="arabic simple">
<li><p>flat_atomic</p></li>
<li><p>s_waitcnt vmcnt(0) &amp;
lgkmcnt(0)</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>If OpenCL, omit
lgkmcnt(0).</p></li>
<li><p>Must happen before
following
buffer_wbinvl1_vol.</p></li>
<li><p>Ensures the
atomicrmw has
completed before
invalidating the
cache.</p></li>
</ul>
</div></blockquote>
<ol class="arabic simple" start="3">
<li><p>buffer_wbinvl1_vol</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>Must happen before
any following
global/generic
load/load
atomic/atomicrmw.</p></li>
<li><p>Ensures that
following loads
will not see stale
global data.</p></li>
</ul>
</div></blockquote>
</td>
<td><ol class="arabic simple">
<li><p>flat_atomic</p></li>
<li><p>s_waitcnt vm/vscnt(0) &amp;
lgkmcnt(0)</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>If OpenCL, omit
lgkmcnt(0).</p></li>
<li><p>Use vmcnt if atomic with
return and vscnt if atomic
with no-return.</p></li>
<li><p>Must happen before
following
buffer_gl*_inv.</p></li>
<li><p>Ensures the
atomicrmw has
completed before
invalidating the
caches.</p></li>
</ul>
</div></blockquote>
<ol class="arabic simple" start="3">
<li><p>buffer_gl0_inv;
buffer_gl1_inv</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>Must happen before
any following
global/generic
load/load
atomic/atomicrmw.</p></li>
<li><p>Ensures that
following loads
will not see stale
global data.</p></li>
</ul>
</div></blockquote>
</td>
</tr>
<tr class="row-odd"><td><p>fence</p></td>
<td><p>acquire</p></td>
<td><ul class="simple">
<li><p>singlethread</p></li>
<li><p>wavefront</p></li>
</ul>
</td>
<td><p><em>none</em></p></td>
<td><p><em>none</em></p></td>
<td><p><em>none</em></p></td>
</tr>
<tr class="row-even"><td><p>fence</p></td>
<td><p>acquire</p></td>
<td><ul class="simple">
<li><p>workgroup</p></li>
</ul>
</td>
<td><p><em>none</em></p></td>
<td><ol class="arabic simple">
<li><p>s_waitcnt lgkmcnt(0)</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>If OpenCL and
address space is
not generic, omit.</p></li>
<li><p>However, since LLVM
currently has no
address space on
the fence need to
conservatively
always generate. If
fence had an
address space then
set to address
space of OpenCL
fence flag, or to
generic if both
local and global
flags are
specified.</p></li>
<li><p>Must happen after
any preceding
local/generic load
atomic/atomicrmw
with an equal or
wider sync scope
and memory ordering
stronger than
unordered (this is
termed the
fence-paired-atomic).</p></li>
<li><p>Must happen before
any following
global/generic
load/load
atomic/store/store
atomic/atomicrmw.</p></li>
<li><p>Ensures any
following global
data read is no
older than the
value read by the
fence-paired-atomic.</p></li>
</ul>
</div></blockquote>
</td>
<td><ol class="arabic simple">
<li><p>s_waitcnt lgkmcnt(0) &amp;
vmcnt(0) &amp; vscnt(0)</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>If CU wavefront execution mode, omit vmcnt and
vscnt.</p></li>
<li><p>If OpenCL and
address space is
not generic, omit
lgkmcnt(0).</p></li>
<li><p>If OpenCL and
address space is
local, omit
vmcnt(0) and vscnt(0).</p></li>
<li><p>However, since LLVM
currently has no
address space on
the fence need to
conservatively
always generate. If
fence had an
address space then
set to address
space of OpenCL
fence flag, or to
generic if both
local and global
flags are
specified.</p></li>
<li><p>Could be split into
separate s_waitcnt
vmcnt(0), s_waitcnt
vscnt(0) and s_waitcnt
lgkmcnt(0) to allow
them to be
independently moved
according to the
following rules.</p></li>
<li><p>s_waitcnt vmcnt(0)
must happen after
any preceding
global/generic load
atomic/
atomicrmw-with-return-value
with an equal or
wider sync scope
and memory ordering
stronger than
unordered (this is
termed the
fence-paired-atomic).</p></li>
<li><p>s_waitcnt vscnt(0)
must happen after
any preceding
global/generic
atomicrmw-no-return-value
with an equal or
wider sync scope
and memory ordering
stronger than
unordered (this is
termed the
fence-paired-atomic).</p></li>
<li><p>s_waitcnt lgkmcnt(0)
must happen after
any preceding
local/generic load
atomic/atomicrmw
with an equal or
wider sync scope
and memory ordering
stronger than
unordered (this is
termed the
fence-paired-atomic).</p></li>
<li><p>Must happen before
the following
buffer_gl0_inv.</p></li>
<li><p>Ensures that the
fence-paired atomic
has completed
before invalidating
the
cache. Therefore
any following
locations read must
be no older than
the value read by
the
fence-paired-atomic.</p></li>
</ul>
</div></blockquote>
<ol class="arabic simple" start="3">
<li><p>buffer_gl0_inv</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>If CU wavefront execution mode, omit.</p></li>
<li><p>Ensures that
following
loads will not see
stale data.</p></li>
</ul>
</div></blockquote>
</td>
</tr>
<tr class="row-odd"><td><p>fence</p></td>
<td><p>acquire</p></td>
<td><ul class="simple">
<li><p>agent</p></li>
<li><p>system</p></li>
</ul>
</td>
<td><p><em>none</em></p></td>
<td><ol class="arabic simple">
<li><p>s_waitcnt lgkmcnt(0) &amp;
vmcnt(0)</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>If OpenCL and
address space is
not generic, omit
lgkmcnt(0).</p></li>
<li><p>However, since LLVM
currently has no
address space on
the fence need to
conservatively
always generate
(see comment for
previous fence).</p></li>
<li><p>Could be split into
separate s_waitcnt
vmcnt(0) and
s_waitcnt
lgkmcnt(0) to allow
them to be
independently moved
according to the
following rules.</p></li>
<li><p>s_waitcnt vmcnt(0)
must happen after
any preceding
global/generic load
atomic/atomicrmw
with an equal or
wider sync scope
and memory ordering
stronger than
unordered (this is
termed the
fence-paired-atomic).</p></li>
<li><p>s_waitcnt lgkmcnt(0)
must happen after
any preceding
local/generic load
atomic/atomicrmw
with an equal or
wider sync scope
and memory ordering
stronger than
unordered (this is
termed the
fence-paired-atomic).</p></li>
<li><p>Must happen before
the following
buffer_wbinvl1_vol.</p></li>
<li><p>Ensures that the
fence-paired atomic
has completed
before invalidating
the
cache. Therefore
any following
locations read must
be no older than
the value read by
the
fence-paired-atomic.</p></li>
</ul>
</div></blockquote>
<ol class="arabic simple" start="2">
<li><p>buffer_wbinvl1_vol</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>Must happen before any
following global/generic
load/load
atomic/store/store
atomic/atomicrmw.</p></li>
<li><p>Ensures that
following loads
will not see stale
global data.</p></li>
</ul>
</div></blockquote>
</td>
<td><ol class="arabic simple">
<li><p>s_waitcnt lgkmcnt(0) &amp;
vmcnt(0) &amp; vscnt(0)</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>If OpenCL and
address space is
not generic, omit
lgkmcnt(0).</p></li>
<li><p>If OpenCL and
address space is
local, omit
vmcnt(0) and vscnt(0).</p></li>
<li><p>However, since LLVM
currently has no
address space on
the fence need to
conservatively
always generate
(see comment for
previous fence).</p></li>
<li><p>Could be split into
separate s_waitcnt
vmcnt(0), s_waitcnt
vscnt(0) and s_waitcnt
lgkmcnt(0) to allow
them to be
independently moved
according to the
following rules.</p></li>
<li><p>s_waitcnt vmcnt(0)
must happen after
any preceding
global/generic load
atomic/
atomicrmw-with-return-value
with an equal or
wider sync scope
and memory ordering
stronger than
unordered (this is
termed the
fence-paired-atomic).</p></li>
<li><p>s_waitcnt vscnt(0)
must happen after
any preceding
global/generic
atomicrmw-no-return-value
with an equal or
wider sync scope
and memory ordering
stronger than
unordered (this is
termed the
fence-paired-atomic).</p></li>
<li><p>s_waitcnt lgkmcnt(0)
must happen after
any preceding
local/generic load
atomic/atomicrmw
with an equal or
wider sync scope
and memory ordering
stronger than
unordered (this is
termed the
fence-paired-atomic).</p></li>
<li><p>Must happen before
the following
buffer_gl*_inv.</p></li>
<li><p>Ensures that the
fence-paired atomic
has completed
before invalidating
the
caches. Therefore
any following
locations read must
be no older than
the value read by
the
fence-paired-atomic.</p></li>
</ul>
</div></blockquote>
<ol class="arabic simple" start="2">
<li><p>buffer_gl0_inv;
buffer_gl1_inv</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>Must happen before any
following global/generic
load/load
atomic/store/store
atomic/atomicrmw.</p></li>
<li><p>Ensures that
following loads
will not see stale
global data.</p></li>
</ul>
</div></blockquote>
</td>
</tr>
<tr class="row-even"><td colspan="6"><p><strong>Release Atomic</strong></p></td>
</tr>
<tr class="row-odd"><td><p>store atomic</p></td>
<td><p>release</p></td>
<td><ul class="simple">
<li><p>singlethread</p></li>
<li><p>wavefront</p></li>
</ul>
</td>
<td><ul class="simple">
<li><p>global</p></li>
<li><p>local</p></li>
<li><p>generic</p></li>
</ul>
</td>
<td><ol class="arabic simple">
<li><p>buffer/global/ds/flat_store</p></li>
</ol>
</td>
<td><ol class="arabic simple">
<li><p>buffer/global/ds/flat_store</p></li>
</ol>
</td>
</tr>
<tr class="row-even"><td><p>store atomic</p></td>
<td><p>release</p></td>
<td><ul class="simple">
<li><p>workgroup</p></li>
</ul>
</td>
<td><ul class="simple">
<li><p>global</p></li>
</ul>
</td>
<td><ol class="arabic simple">
<li><p>s_waitcnt lgkmcnt(0)</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>If OpenCL, omit.</p></li>
<li><p>Must happen after
any preceding
local/generic
load/store/load
atomic/store
atomic/atomicrmw.</p></li>
<li><p>Must happen before
the following
store.</p></li>
<li><p>Ensures that all
memory operations
to local have
completed before
performing the
store that is being
released.</p></li>
</ul>
</div></blockquote>
<ol class="arabic simple" start="2">
<li><p>buffer/global/flat_store</p></li>
</ol>
</td>
<td><ol class="arabic simple">
<li><p>s_waitcnt lgkmcnt(0) &amp;
vmcnt(0) &amp; vscnt(0)</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>If CU wavefront execution mode, omit vmcnt and
vscnt.</p></li>
<li><p>If OpenCL, omit
lgkmcnt(0).</p></li>
<li><p>Could be split into
separate s_waitcnt
vmcnt(0), s_waitcnt
vscnt(0) and s_waitcnt
lgkmcnt(0) to allow
them to be
independently moved
according to the
following rules.</p></li>
<li><p>s_waitcnt vmcnt(0)
must happen after
any preceding
global/generic load/load
atomic/
atomicrmw-with-return-value.</p></li>
<li><p>s_waitcnt vscnt(0)
must happen after
any preceding
global/generic
store/store
atomic/
atomicrmw-no-return-value.</p></li>
<li><p>s_waitcnt lgkmcnt(0)
must happen after
any preceding
local/generic
load/store/load
atomic/store
atomic/atomicrmw.</p></li>
<li><p>Must happen before
the following
store.</p></li>
<li><p>Ensures that all
memory operations
have
completed before
performing the
store that is being
released.</p></li>
</ul>
</div></blockquote>
<ol class="arabic simple" start="2">
<li><p>buffer/global_store</p></li>
</ol>
</td>
</tr>
<tr class="row-odd"><td><p>store atomic</p></td>
<td><p>release</p></td>
<td><ul class="simple">
<li><p>workgroup</p></li>
</ul>
</td>
<td><ul class="simple">
<li><p>local</p></li>
</ul>
</td>
<td><ol class="arabic simple">
<li><p>ds_store</p></li>
</ol>
</td>
<td><ol class="arabic simple">
<li><p>waitcnt vmcnt(0) &amp; vscnt(0)</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>If CU wavefront execution mode, omit.</p></li>
<li><p>If OpenCL, omit.</p></li>
<li><p>Could be split into
separate s_waitcnt
vmcnt(0) and s_waitcnt
vscnt(0) to allow
them to be
independently moved
according to the
following rules.</p></li>
<li><p>s_waitcnt vmcnt(0)
must happen after
any preceding
global/generic load/load
atomic/
atomicrmw-with-return-value.</p></li>
<li><p>s_waitcnt vscnt(0)
must happen after
any preceding
global/generic
store/store atomic/
atomicrmw-no-return-value.</p></li>
<li><p>Must happen before
the following
store.</p></li>
<li><p>Ensures that all
global memory
operations have
completed before
performing the
store that is being
released.</p></li>
</ul>
</div></blockquote>
<ol class="arabic simple" start="2">
<li><p>ds_store</p></li>
</ol>
</td>
</tr>
<tr class="row-even"><td><p>store atomic</p></td>
<td><p>release</p></td>
<td><ul class="simple">
<li><p>workgroup</p></li>
</ul>
</td>
<td><ul class="simple">
<li><p>generic</p></li>
</ul>
</td>
<td><ol class="arabic simple">
<li><p>s_waitcnt lgkmcnt(0)</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>If OpenCL, omit.</p></li>
<li><p>Must happen after
any preceding
local/generic
load/store/load
atomic/store
atomic/atomicrmw.</p></li>
<li><p>Must happen before
the following
store.</p></li>
<li><p>Ensures that all
memory operations
to local have
completed before
performing the
store that is being
released.</p></li>
</ul>
</div></blockquote>
<ol class="arabic simple" start="2">
<li><p>flat_store</p></li>
</ol>
</td>
<td><ol class="arabic simple">
<li><p>s_waitcnt lgkmcnt(0) &amp;
vmcnt(0) &amp; vscnt(0)</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>If CU wavefront execution mode, omit vmcnt and
vscnt.</p></li>
<li><p>If OpenCL, omit
lgkmcnt(0).</p></li>
<li><p>Could be split into
separate s_waitcnt
vmcnt(0), s_waitcnt
vscnt(0) and s_waitcnt
lgkmcnt(0) to allow
them to be
independently moved
according to the
following rules.</p></li>
<li><p>s_waitcnt vmcnt(0)
must happen after
any preceding
global/generic load/load
atomic/
atomicrmw-with-return-value.</p></li>
<li><p>s_waitcnt vscnt(0)
must happen after
any preceding
global/generic
store/store
atomic/
atomicrmw-no-return-value.</p></li>
<li><p>s_waitcnt lgkmcnt(0)
must happen after
any preceding
local/generic load/store/load
atomic/store atomic/atomicrmw.</p></li>
<li><p>Must happen before
the following
store.</p></li>
<li><p>Ensures that all
memory operations
have
completed before
performing the
store that is being
released.</p></li>
</ul>
</div></blockquote>
<ol class="arabic simple" start="2">
<li><p>flat_store</p></li>
</ol>
</td>
</tr>
<tr class="row-odd"><td><p>store atomic</p></td>
<td><p>release</p></td>
<td><ul class="simple">
<li><p>agent</p></li>
<li><p>system</p></li>
</ul>
</td>
<td><ul class="simple">
<li><p>global</p></li>
<li><p>generic</p></li>
</ul>
</td>
<td><ol class="arabic simple">
<li><p>s_waitcnt lgkmcnt(0) &amp;
vmcnt(0)</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>If OpenCL, omit
lgkmcnt(0).</p></li>
<li><p>Could be split into
separate s_waitcnt
vmcnt(0) and
s_waitcnt
lgkmcnt(0) to allow
them to be
independently moved
according to the
following rules.</p></li>
<li><p>s_waitcnt vmcnt(0)
must happen after
any preceding
global/generic
load/store/load
atomic/store
atomic/atomicrmw.</p></li>
<li><p>s_waitcnt lgkmcnt(0)
must happen after
any preceding
local/generic
load/store/load
atomic/store
atomic/atomicrmw.</p></li>
<li><p>Must happen before
the following
store.</p></li>
<li><p>Ensures that all
memory operations
to memory have
completed before
performing the
store that is being
released.</p></li>
</ul>
</div></blockquote>
<ol class="arabic simple" start="2">
<li><p>buffer/global/ds/flat_store</p></li>
</ol>
</td>
<td><blockquote>
<div><ol class="arabic simple">
<li><p>s_waitcnt lgkmcnt(0) &amp;
vmcnt(0) &amp; vscnt(0)</p></li>
</ol>
<ul class="simple">
<li><p>If OpenCL, omit
lgkmcnt(0).</p></li>
<li><p>Could be split into
separate s_waitcnt
vmcnt(0), s_waitcnt vscnt(0)
and s_waitcnt
lgkmcnt(0) to allow
them to be
independently moved
according to the
following rules.</p></li>
<li><p>s_waitcnt vmcnt(0)
must happen after
any preceding
global/generic
load/load
atomic/
atomicrmw-with-return-value.</p></li>
<li><p>s_waitcnt vscnt(0)
must happen after
any preceding
global/generic
store/store atomic/
atomicrmw-no-return-value.</p></li>
<li><p>s_waitcnt lgkmcnt(0)
must happen after
any preceding
local/generic
load/store/load
atomic/store
atomic/atomicrmw.</p></li>
<li><p>Must happen before
the following
store.</p></li>
<li><p>Ensures that all
memory operations
to memory have
completed before
performing the
store that is being
released.</p></li>
</ul>
</div></blockquote>
<ol class="arabic simple" start="2">
<li><p>buffer/global/ds/flat_store</p></li>
</ol>
</td>
</tr>
<tr class="row-even"><td><p>atomicrmw</p></td>
<td><p>release</p></td>
<td><ul class="simple">
<li><p>singlethread</p></li>
<li><p>wavefront</p></li>
</ul>
</td>
<td><ul class="simple">
<li><p>global</p></li>
<li><p>local</p></li>
<li><p>generic</p></li>
</ul>
</td>
<td><ol class="arabic simple">
<li><p>buffer/global/ds/flat_atomic</p></li>
</ol>
</td>
<td><ol class="arabic simple">
<li><p>buffer/global/ds/flat_atomic</p></li>
</ol>
</td>
</tr>
<tr class="row-odd"><td><p>atomicrmw</p></td>
<td><p>release</p></td>
<td><ul class="simple">
<li><p>workgroup</p></li>
</ul>
</td>
<td><ul class="simple">
<li><p>global</p></li>
</ul>
</td>
<td><ol class="arabic simple">
<li><p>s_waitcnt lgkmcnt(0)</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>If OpenCL, omit.</p></li>
<li><p>Must happen after
any preceding
local/generic
load/store/load
atomic/store
atomic/atomicrmw.</p></li>
<li><p>Must happen before
the following
atomicrmw.</p></li>
<li><p>Ensures that all
memory operations
to local have
completed before
performing the
atomicrmw that is
being released.</p></li>
</ul>
</div></blockquote>
<ol class="arabic simple" start="2">
<li><p>buffer/global/flat_atomic</p></li>
</ol>
</td>
<td><ol class="arabic simple">
<li><p>s_waitcnt lgkmcnt(0) &amp;
vmcnt(0) &amp; vscnt(0)</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>If CU wavefront execution mode, omit vmcnt and
vscnt.</p></li>
<li><p>Could be split into
separate s_waitcnt
vmcnt(0), s_waitcnt
vscnt(0) and s_waitcnt
lgkmcnt(0) to allow
them to be
independently moved
according to the
following rules.</p></li>
<li><p>s_waitcnt vmcnt(0)
must happen after
any preceding
global/generic load/load
atomic/
atomicrmw-with-return-value.</p></li>
<li><p>s_waitcnt vscnt(0)
must happen after
any preceding
global/generic
store/store
atomic/
atomicrmw-no-return-value.</p></li>
<li><p>s_waitcnt lgkmcnt(0)
must happen after
any preceding
local/generic
load/store/load
atomic/store
atomic/atomicrmw.</p></li>
<li><p>Must happen before
the following
atomicrmw.</p></li>
<li><p>Ensures that all
memory operations
have
completed before
performing the
atomicrmw that is
being released.</p></li>
</ul>
</div></blockquote>
<ol class="arabic simple" start="2">
<li><p>buffer/global_atomic</p></li>
</ol>
</td>
</tr>
<tr class="row-even"><td><p>atomicrmw</p></td>
<td><p>release</p></td>
<td><ul class="simple">
<li><p>workgroup</p></li>
</ul>
</td>
<td><ul class="simple">
<li><p>local</p></li>
</ul>
</td>
<td><ol class="arabic simple">
<li><p>ds_atomic</p></li>
</ol>
</td>
<td><ol class="arabic simple">
<li><p>waitcnt vmcnt(0) &amp; vscnt(0)</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>If CU wavefront execution mode, omit.</p></li>
<li><p>If OpenCL, omit.</p></li>
<li><p>Could be split into
separate s_waitcnt
vmcnt(0) and s_waitcnt
vscnt(0) to allow
them to be
independently moved
according to the
following rules.</p></li>
<li><p>s_waitcnt vmcnt(0)
must happen after
any preceding
global/generic load/load
atomic/
atomicrmw-with-return-value.</p></li>
<li><p>s_waitcnt vscnt(0)
must happen after
any preceding
global/generic
store/store atomic/
atomicrmw-no-return-value.</p></li>
<li><p>Must happen before
the following
store.</p></li>
<li><p>Ensures that all
global memory
operations have
completed before
performing the
store that is being
released.</p></li>
</ul>
</div></blockquote>
<ol class="arabic simple" start="2">
<li><p>ds_atomic</p></li>
</ol>
</td>
</tr>
<tr class="row-odd"><td><p>atomicrmw</p></td>
<td><p>release</p></td>
<td><ul class="simple">
<li><p>workgroup</p></li>
</ul>
</td>
<td><ul class="simple">
<li><p>generic</p></li>
</ul>
</td>
<td><ol class="arabic simple">
<li><p>s_waitcnt lgkmcnt(0)</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>If OpenCL, omit.</p></li>
<li><p>Must happen after
any preceding
local/generic
load/store/load
atomic/store
atomic/atomicrmw.</p></li>
<li><p>Must happen before
the following
atomicrmw.</p></li>
<li><p>Ensures that all
memory operations
to local have
completed before
performing the
atomicrmw that is
being released.</p></li>
</ul>
</div></blockquote>
<ol class="arabic simple" start="2">
<li><p>flat_atomic</p></li>
</ol>
</td>
<td><ol class="arabic simple">
<li><p>s_waitcnt lgkmcnt(0) &amp;
vmcnt(0) &amp; vscnt(0)</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>If CU wavefront execution mode, omit vmcnt and
vscnt.</p></li>
<li><p>If OpenCL, omit
waitcnt lgkmcnt(0).</p></li>
<li><p>Could be split into
separate s_waitcnt
vmcnt(0), s_waitcnt
vscnt(0) and s_waitcnt
lgkmcnt(0) to allow
them to be
independently moved
according to the
following rules.</p></li>
<li><p>s_waitcnt vmcnt(0)
must happen after
any preceding
global/generic load/load
atomic/
atomicrmw-with-return-value.</p></li>
<li><p>s_waitcnt vscnt(0)
must happen after
any preceding
global/generic
store/store
atomic/
atomicrmw-no-return-value.</p></li>
<li><p>s_waitcnt lgkmcnt(0)
must happen after
any preceding
local/generic load/store/load
atomic/store atomic/atomicrmw.</p></li>
<li><p>Must happen before
the following
atomicrmw.</p></li>
<li><p>Ensures that all
memory operations
have
completed before
performing the
atomicrmw that is
being released.</p></li>
</ul>
</div></blockquote>
<ol class="arabic simple" start="2">
<li><p>flat_atomic</p></li>
</ol>
</td>
</tr>
<tr class="row-even"><td><p>atomicrmw</p></td>
<td><p>release</p></td>
<td><ul class="simple">
<li><p>agent</p></li>
<li><p>system</p></li>
</ul>
</td>
<td><ul class="simple">
<li><p>global</p></li>
<li><p>generic</p></li>
</ul>
</td>
<td><ol class="arabic simple">
<li><p>s_waitcnt lgkmcnt(0) &amp;
vmcnt(0)</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>If OpenCL, omit
lgkmcnt(0).</p></li>
<li><p>Could be split into
separate s_waitcnt
vmcnt(0) and
s_waitcnt
lgkmcnt(0) to allow
them to be
independently moved
according to the
following rules.</p></li>
<li><p>s_waitcnt vmcnt(0)
must happen after
any preceding
global/generic
load/store/load
atomic/store
atomic/atomicrmw.</p></li>
<li><p>s_waitcnt lgkmcnt(0)
must happen after
any preceding
local/generic
load/store/load
atomic/store
atomic/atomicrmw.</p></li>
<li><p>Must happen before
the following
atomicrmw.</p></li>
<li><p>Ensures that all
memory operations
to global and local
have completed
before performing
the atomicrmw that
is being released.</p></li>
</ul>
</div></blockquote>
<ol class="arabic simple" start="2">
<li><p>buffer/global/ds/flat_atomic</p></li>
</ol>
</td>
<td><ol class="arabic simple">
<li><dl class="simple">
<dt>s_waitcnt lkkmcnt(0) &amp;</dt><dd><p>vmcnt(0) &amp; vscnt(0)</p>
</dd>
</dl>
</li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>If OpenCL, omit
lgkmcnt(0).</p></li>
<li><p>Could be split into
separate s_waitcnt
vmcnt(0), s_waitcnt
vscnt(0) and s_waitcnt
lgkmcnt(0) to allow
them to be
independently moved
according to the
following rules.</p></li>
<li><p>s_waitcnt vmcnt(0)
must happen after
any preceding
global/generic
load/load atomic/
atomicrmw-with-return-value.</p></li>
<li><p>s_waitcnt vscnt(0)
must happen after
any preceding
global/generic
store/store atomic/
atomicrmw-no-return-value.</p></li>
<li><p>s_waitcnt lgkmcnt(0)
must happen after
any preceding
local/generic
load/store/load
atomic/store
atomic/atomicrmw.</p></li>
<li><p>Must happen before
the following
atomicrmw.</p></li>
<li><p>Ensures that all
memory operations
to global and local
have completed
before performing
the atomicrmw that
is being released.</p></li>
</ul>
</div></blockquote>
<ol class="arabic simple" start="2">
<li><p>buffer/global/ds/flat_atomic</p></li>
</ol>
</td>
</tr>
<tr class="row-odd"><td><p>fence</p></td>
<td><p>release</p></td>
<td><ul class="simple">
<li><p>singlethread</p></li>
<li><p>wavefront</p></li>
</ul>
</td>
<td><p><em>none</em></p></td>
<td><p><em>none</em></p></td>
<td><p><em>none</em></p></td>
</tr>
<tr class="row-even"><td><p>fence</p></td>
<td><p>release</p></td>
<td><ul class="simple">
<li><p>workgroup</p></li>
</ul>
</td>
<td><p><em>none</em></p></td>
<td><ol class="arabic simple">
<li><p>s_waitcnt lgkmcnt(0)</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>If OpenCL and
address space is
not generic, omit.</p></li>
<li><p>However, since LLVM
currently has no
address space on
the fence need to
conservatively
always generate. If
fence had an
address space then
set to address
space of OpenCL
fence flag, or to
generic if both
local and global
flags are
specified.</p></li>
<li><p>Must happen after
any preceding
local/generic
load/load
atomic/store/store
atomic/atomicrmw.</p></li>
<li><p>Must happen before
any following store
atomic/atomicrmw
with an equal or
wider sync scope
and memory ordering
stronger than
unordered (this is
termed the
fence-paired-atomic).</p></li>
<li><p>Ensures that all
memory operations
to local have
completed before
performing the
following
fence-paired-atomic.</p></li>
</ul>
</div></blockquote>
</td>
<td><ol class="arabic simple">
<li><p>s_waitcnt lgkmcnt(0) &amp;
vmcnt(0) &amp; vscnt(0)</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>If CU wavefront execution mode, omit vmcnt and
vscnt.</p></li>
<li><p>If OpenCL and
address space is
not generic, omit
lgkmcnt(0).</p></li>
<li><p>If OpenCL and
address space is
local, omit
vmcnt(0) and vscnt(0).</p></li>
<li><p>However, since LLVM
currently has no
address space on
the fence need to
conservatively
always generate. If
fence had an
address space then
set to address
space of OpenCL
fence flag, or to
generic if both
local and global
flags are
specified.</p></li>
<li><p>Could be split into
separate s_waitcnt
vmcnt(0), s_waitcnt
vscnt(0) and s_waitcnt
lgkmcnt(0) to allow
them to be
independently moved
according to the
following rules.</p></li>
<li><p>s_waitcnt vmcnt(0)
must happen after
any preceding
global/generic
load/load
atomic/
atomicrmw-with-return-value.</p></li>
<li><p>s_waitcnt vscnt(0)
must happen after
any preceding
global/generic
store/store atomic/
atomicrmw-no-return-value.</p></li>
<li><p>s_waitcnt lgkmcnt(0)
must happen after
any preceding
local/generic
load/store/load
atomic/store atomic/
atomicrmw.</p></li>
<li><p>Must happen before
any following store
atomic/atomicrmw
with an equal or
wider sync scope
and memory ordering
stronger than
unordered (this is
termed the
fence-paired-atomic).</p></li>
<li><p>Ensures that all
memory operations
have
completed before
performing the
following
fence-paired-atomic.</p></li>
</ul>
</div></blockquote>
</td>
</tr>
<tr class="row-odd"><td><p>fence</p></td>
<td><p>release</p></td>
<td><ul class="simple">
<li><p>agent</p></li>
<li><p>system</p></li>
</ul>
</td>
<td><p><em>none</em></p></td>
<td><ol class="arabic simple">
<li><p>s_waitcnt lgkmcnt(0) &amp;
vmcnt(0)</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>If OpenCL and
address space is
not generic, omit
lgkmcnt(0).</p></li>
<li><p>If OpenCL and
address space is
local, omit
vmcnt(0).</p></li>
<li><p>However, since LLVM
currently has no
address space on
the fence need to
conservatively
always generate. If
fence had an
address space then
set to address
space of OpenCL
fence flag, or to
generic if both
local and global
flags are
specified.</p></li>
<li><p>Could be split into
separate s_waitcnt
vmcnt(0) and
s_waitcnt
lgkmcnt(0) to allow
them to be
independently moved
according to the
following rules.</p></li>
<li><p>s_waitcnt vmcnt(0)
must happen after
any preceding
global/generic
load/store/load
atomic/store
atomic/atomicrmw.</p></li>
<li><p>s_waitcnt lgkmcnt(0)
must happen after
any preceding
local/generic
load/store/load
atomic/store
atomic/atomicrmw.</p></li>
<li><p>Must happen before
any following store
atomic/atomicrmw
with an equal or
wider sync scope
and memory ordering
stronger than
unordered (this is
termed the
fence-paired-atomic).</p></li>
<li><p>Ensures that all
memory operations
have
completed before
performing the
following
fence-paired-atomic.</p></li>
</ul>
</div></blockquote>
</td>
<td><ol class="arabic simple">
<li><p>s_waitcnt lgkmcnt(0) &amp;
vmcnt(0) &amp; vscnt(0)</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>If OpenCL and
address space is
not generic, omit
lgkmcnt(0).</p></li>
<li><p>If OpenCL and
address space is
local, omit
vmcnt(0) and vscnt(0).</p></li>
<li><p>However, since LLVM
currently has no
address space on
the fence need to
conservatively
always generate. If
fence had an
address space then
set to address
space of OpenCL
fence flag, or to
generic if both
local and global
flags are
specified.</p></li>
<li><p>Could be split into
separate s_waitcnt
vmcnt(0), s_waitcnt
vscnt(0) and s_waitcnt
lgkmcnt(0) to allow
them to be
independently moved
according to the
following rules.</p></li>
<li><p>s_waitcnt vmcnt(0)
must happen after
any preceding
global/generic
load/load atomic/
atomicrmw-with-return-value.</p></li>
<li><p>s_waitcnt vscnt(0)
must happen after
any preceding
global/generic
store/store atomic/
atomicrmw-no-return-value.</p></li>
<li><p>s_waitcnt lgkmcnt(0)
must happen after
any preceding
local/generic
load/store/load
atomic/store
atomic/atomicrmw.</p></li>
<li><p>Must happen before
any following store
atomic/atomicrmw
with an equal or
wider sync scope
and memory ordering
stronger than
unordered (this is
termed the
fence-paired-atomic).</p></li>
<li><p>Ensures that all
memory operations
have
completed before
performing the
following
fence-paired-atomic.</p></li>
</ul>
</div></blockquote>
</td>
</tr>
<tr class="row-even"><td colspan="6"><p><strong>Acquire-Release Atomic</strong></p></td>
</tr>
<tr class="row-odd"><td><p>atomicrmw</p></td>
<td><p>acq_rel</p></td>
<td><ul class="simple">
<li><p>singlethread</p></li>
<li><p>wavefront</p></li>
</ul>
</td>
<td><ul class="simple">
<li><p>global</p></li>
<li><p>local</p></li>
<li><p>generic</p></li>
</ul>
</td>
<td><ol class="arabic simple">
<li><p>buffer/global/ds/flat_atomic</p></li>
</ol>
</td>
<td><ol class="arabic simple">
<li><p>buffer/global/ds/flat_atomic</p></li>
</ol>
</td>
</tr>
<tr class="row-even"><td><p>atomicrmw</p></td>
<td><p>acq_rel</p></td>
<td><ul class="simple">
<li><p>workgroup</p></li>
</ul>
</td>
<td><ul class="simple">
<li><p>global</p></li>
</ul>
</td>
<td><ol class="arabic simple">
<li><p>s_waitcnt lgkmcnt(0)</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>If OpenCL, omit.</p></li>
<li><p>Must happen after
any preceding
local/generic
load/store/load
atomic/store
atomic/atomicrmw.</p></li>
<li><p>Must happen before
the following
atomicrmw.</p></li>
<li><p>Ensures that all
memory operations
to local have
completed before
performing the
atomicrmw that is
being released.</p></li>
</ul>
</div></blockquote>
<ol class="arabic simple" start="2">
<li><p>buffer/global/flat_atomic</p></li>
</ol>
</td>
<td><ol class="arabic simple">
<li><p>s_waitcnt lgkmcnt(0) &amp;
vmcnt(0) &amp; vscnt(0)</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>If CU wavefront execution mode, omit vmcnt and
vscnt.</p></li>
<li><p>If OpenCL, omit
s_waitcnt lgkmcnt(0).</p></li>
<li><p>Must happen after
any preceding
local/generic
load/store/load
atomic/store
atomic/atomicrmw.</p></li>
<li><p>Could be split into
separate s_waitcnt
vmcnt(0), s_waitcnt
vscnt(0) and s_waitcnt
lgkmcnt(0) to allow
them to be
independently moved
according to the
following rules.</p></li>
<li><p>s_waitcnt vmcnt(0)
must happen after
any preceding
global/generic load/load
atomic/
atomicrmw-with-return-value.</p></li>
<li><p>s_waitcnt vscnt(0)
must happen after
any preceding
global/generic
store/store
atomic/
atomicrmw-no-return-value.</p></li>
<li><p>s_waitcnt lgkmcnt(0)
must happen after
any preceding
local/generic load/store/load
atomic/store atomic/atomicrmw.</p></li>
<li><p>Must happen before
the following
atomicrmw.</p></li>
<li><p>Ensures that all
memory operations
have
completed before
performing the
atomicrmw that is
being released.</p></li>
</ul>
</div></blockquote>
<ol class="arabic simple" start="2">
<li><p>buffer/global_atomic</p></li>
<li><p>s_waitcnt vm/vscnt(0)</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>If CU wavefront execution mode, omit vm/vscnt.</p></li>
<li><p>Use vmcnt if atomic with
return and vscnt if atomic
with no-return.
waitcnt lgkmcnt(0).</p></li>
<li><p>Must happen before
the following
buffer_gl0_inv.</p></li>
<li><p>Ensures any
following global
data read is no
older than the
atomicrmw value
being acquired.</p></li>
</ul>
</div></blockquote>
<ol class="arabic simple" start="4">
<li><p>buffer_gl0_inv</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>If CU wavefront execution mode, omit.</p></li>
<li><p>Ensures that
following
loads will not see
stale data.</p></li>
</ul>
</div></blockquote>
</td>
</tr>
<tr class="row-odd"><td><p>atomicrmw</p></td>
<td><p>acq_rel</p></td>
<td><ul class="simple">
<li><p>workgroup</p></li>
</ul>
</td>
<td><ul class="simple">
<li><p>local</p></li>
</ul>
</td>
<td><ol class="arabic simple">
<li><p>ds_atomic</p></li>
<li><p>s_waitcnt lgkmcnt(0)</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>If OpenCL, omit.</p></li>
<li><p>Must happen before
any following
global/generic
load/load
atomic/store/store
atomic/atomicrmw.</p></li>
<li><p>Ensures any
following global
data read is no
older than the load
atomic value being
acquired.</p></li>
</ul>
</div></blockquote>
</td>
<td><ol class="arabic simple">
<li><p>waitcnt vmcnt(0) &amp; vscnt(0)</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>If CU wavefront execution mode, omit.</p></li>
<li><p>If OpenCL, omit.</p></li>
<li><p>Could be split into
separate s_waitcnt
vmcnt(0) and s_waitcnt
vscnt(0) to allow
them to be
independently moved
according to the
following rules.</p></li>
<li><p>s_waitcnt vmcnt(0)
must happen after
any preceding
global/generic load/load
atomic/
atomicrmw-with-return-value.</p></li>
<li><p>s_waitcnt vscnt(0)
must happen after
any preceding
global/generic
store/store atomic/
atomicrmw-no-return-value.</p></li>
<li><p>Must happen before
the following
store.</p></li>
<li><p>Ensures that all
global memory
operations have
completed before
performing the
store that is being
released.</p></li>
</ul>
</div></blockquote>
<ol class="arabic simple" start="2">
<li><p>ds_atomic</p></li>
<li><p>s_waitcnt lgkmcnt(0)</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>If OpenCL, omit.</p></li>
<li><p>Must happen before
the following
buffer_gl0_inv.</p></li>
<li><p>Ensures any
following global
data read is no
older than the load
atomic value being
acquired.</p></li>
</ul>
</div></blockquote>
<ol class="arabic simple" start="4">
<li><p>buffer_gl0_inv</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>If CU wavefront execution mode, omit.</p></li>
<li><p>If OpenCL omit.</p></li>
<li><p>Ensures that
following
loads will not see
stale data.</p></li>
</ul>
</div></blockquote>
</td>
</tr>
<tr class="row-even"><td><p>atomicrmw</p></td>
<td><p>acq_rel</p></td>
<td><ul class="simple">
<li><p>workgroup</p></li>
</ul>
</td>
<td><ul class="simple">
<li><p>generic</p></li>
</ul>
</td>
<td><ol class="arabic simple">
<li><p>s_waitcnt lgkmcnt(0)</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>If OpenCL, omit.</p></li>
<li><p>Must happen after
any preceding
local/generic
load/store/load
atomic/store
atomic/atomicrmw.</p></li>
<li><p>Must happen before
the following
atomicrmw.</p></li>
<li><p>Ensures that all
memory operations
to local have
completed before
performing the
atomicrmw that is
being released.</p></li>
</ul>
</div></blockquote>
<ol class="arabic simple" start="2">
<li><p>flat_atomic</p></li>
<li><p>s_waitcnt lgkmcnt(0)</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>If OpenCL, omit.</p></li>
<li><p>Must happen before
any following
global/generic
load/load
atomic/store/store
atomic/atomicrmw.</p></li>
<li><p>Ensures any
following global
data read is no
older than the load
atomic value being
acquired.</p></li>
</ul>
</div></blockquote>
</td>
<td><ol class="arabic simple">
<li><p>s_waitcnt lgkmcnt(0) &amp;
vmcnt(0) &amp; vscnt(0)</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>If CU wavefront execution mode, omit vmcnt and
vscnt.</p></li>
<li><p>If OpenCL, omit
waitcnt lgkmcnt(0).</p></li>
<li><p>Could be split into
separate s_waitcnt
vmcnt(0), s_waitcnt
vscnt(0) and s_waitcnt
lgkmcnt(0) to allow
them to be
independently moved
according to the
following rules.</p></li>
<li><p>s_waitcnt vmcnt(0)
must happen after
any preceding
global/generic load/load
atomic/
atomicrmw-with-return-value.</p></li>
<li><p>s_waitcnt vscnt(0)
must happen after
any preceding
global/generic
store/store
atomic/
atomicrmw-no-return-value.</p></li>
<li><p>s_waitcnt lgkmcnt(0)
must happen after
any preceding
local/generic load/store/load
atomic/store atomic/atomicrmw.</p></li>
<li><p>Must happen before
the following
atomicrmw.</p></li>
<li><p>Ensures that all
memory operations
have
completed before
performing the
atomicrmw that is
being released.</p></li>
</ul>
</div></blockquote>
<ol class="arabic simple" start="2">
<li><p>flat_atomic</p></li>
<li><p>s_waitcnt lgkmcnt(0) &amp;
vm/vscnt(0)</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>If CU wavefront execution mode, omit vm/vscnt.</p></li>
<li><p>If OpenCL, omit
waitcnt lgkmcnt(0).</p></li>
<li><p>Must happen before
the following
buffer_gl0_inv.</p></li>
<li><p>Ensures any
following global
data read is no
older than the load
atomic value being
acquired.</p></li>
</ul>
</div></blockquote>
<ol class="arabic simple" start="3">
<li><p>buffer_gl0_inv</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>If CU wavefront execution mode, omit.</p></li>
<li><p>Ensures that
following
loads will not see
stale data.</p></li>
</ul>
</div></blockquote>
</td>
</tr>
<tr class="row-odd"><td><p>atomicrmw</p></td>
<td><p>acq_rel</p></td>
<td><ul class="simple">
<li><p>agent</p></li>
<li><p>system</p></li>
</ul>
</td>
<td><ul class="simple">
<li><p>global</p></li>
</ul>
</td>
<td><ol class="arabic simple">
<li><p>s_waitcnt lgkmcnt(0) &amp;
vmcnt(0)</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>If OpenCL, omit
lgkmcnt(0).</p></li>
<li><p>Could be split into
separate s_waitcnt
vmcnt(0) and
s_waitcnt
lgkmcnt(0) to allow
them to be
independently moved
according to the
following rules.</p></li>
<li><p>s_waitcnt vmcnt(0)
must happen after
any preceding
global/generic
load/store/load
atomic/store
atomic/atomicrmw.</p></li>
<li><p>s_waitcnt lgkmcnt(0)
must happen after
any preceding
local/generic
load/store/load
atomic/store
atomic/atomicrmw.</p></li>
<li><p>Must happen before
the following
atomicrmw.</p></li>
<li><p>Ensures that all
memory operations
to global have
completed before
performing the
atomicrmw that is
being released.</p></li>
</ul>
</div></blockquote>
<ol class="arabic simple" start="2">
<li><p>buffer/global/flat_atomic</p></li>
<li><p>s_waitcnt vmcnt(0)</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>Must happen before
following
buffer_wbinvl1_vol.</p></li>
<li><p>Ensures the
atomicrmw has
completed before
invalidating the
cache.</p></li>
</ul>
</div></blockquote>
<ol class="arabic simple" start="4">
<li><p>buffer_wbinvl1_vol</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>Must happen before
any following
global/generic
load/load
atomic/atomicrmw.</p></li>
<li><p>Ensures that
following loads
will not see stale
global data.</p></li>
</ul>
</div></blockquote>
</td>
<td><ol class="arabic simple">
<li><p>s_waitcnt lgkmcnt(0) &amp;
vmcnt(0) &amp; vscnt(0)</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>If OpenCL, omit
lgkmcnt(0).</p></li>
<li><p>Could be split into
separate s_waitcnt
vmcnt(0), s_waitcnt
vscnt(0) and s_waitcnt
lgkmcnt(0) to allow
them to be
independently moved
according to the
following rules.</p></li>
<li><p>s_waitcnt vmcnt(0)
must happen after
any preceding
global/generic
load/load atomic/
atomicrmw-with-return-value.</p></li>
<li><p>s_waitcnt vscnt(0)
must happen after
any preceding
global/generic
store/store atomic/
atomicrmw-no-return-value.</p></li>
<li><p>s_waitcnt lgkmcnt(0)
must happen after
any preceding
local/generic
load/store/load
atomic/store
atomic/atomicrmw.</p></li>
<li><p>Must happen before
the following
atomicrmw.</p></li>
<li><p>Ensures that all
memory operations
to global have
completed before
performing the
atomicrmw that is
being released.</p></li>
</ul>
</div></blockquote>
<ol class="arabic simple" start="2">
<li><p>buffer/global_atomic</p></li>
<li><p>s_waitcnt vm/vscnt(0)</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>Use vmcnt if atomic with
return and vscnt if atomic
with no-return.
waitcnt lgkmcnt(0).</p></li>
<li><p>Must happen before
following
buffer_gl*_inv.</p></li>
<li><p>Ensures the
atomicrmw has
completed before
invalidating the
caches.</p></li>
</ul>
</div></blockquote>
<ol class="arabic simple" start="4">
<li><p>buffer_gl0_inv;
buffer_gl1_inv</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>Must happen before
any following
global/generic
load/load
atomic/atomicrmw.</p></li>
<li><p>Ensures that
following loads
will not see stale
global data.</p></li>
</ul>
</div></blockquote>
</td>
</tr>
<tr class="row-even"><td><p>atomicrmw</p></td>
<td><p>acq_rel</p></td>
<td><ul class="simple">
<li><p>agent</p></li>
<li><p>system</p></li>
</ul>
</td>
<td><ul class="simple">
<li><p>generic</p></li>
</ul>
</td>
<td><ol class="arabic simple">
<li><p>s_waitcnt lgkmcnt(0) &amp;
vmcnt(0)</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>If OpenCL, omit
lgkmcnt(0).</p></li>
<li><p>Could be split into
separate s_waitcnt
vmcnt(0) and
s_waitcnt
lgkmcnt(0) to allow
them to be
independently moved
according to the
following rules.</p></li>
<li><p>s_waitcnt vmcnt(0)
must happen after
any preceding
global/generic
load/store/load
atomic/store
atomic/atomicrmw.</p></li>
<li><p>s_waitcnt lgkmcnt(0)
must happen after
any preceding
local/generic
load/store/load
atomic/store
atomic/atomicrmw.</p></li>
<li><p>Must happen before
the following
atomicrmw.</p></li>
<li><p>Ensures that all
memory operations
to global have
completed before
performing the
atomicrmw that is
being released.</p></li>
</ul>
</div></blockquote>
<ol class="arabic simple" start="2">
<li><p>flat_atomic</p></li>
<li><p>s_waitcnt vmcnt(0) &amp;
lgkmcnt(0)</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>If OpenCL, omit
lgkmcnt(0).</p></li>
<li><p>Must happen before
following
buffer_wbinvl1_vol.</p></li>
<li><p>Ensures the
atomicrmw has
completed before
invalidating the
cache.</p></li>
</ul>
</div></blockquote>
<ol class="arabic simple" start="4">
<li><p>buffer_wbinvl1_vol</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>Must happen before
any following
global/generic
load/load
atomic/atomicrmw.</p></li>
<li><p>Ensures that
following loads
will not see stale
global data.</p></li>
</ul>
</div></blockquote>
</td>
<td><ol class="arabic simple">
<li><p>s_waitcnt lgkmcnt(0) &amp;
vmcnt(0) &amp; vscnt(0)</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>If OpenCL, omit
lgkmcnt(0).</p></li>
<li><p>Could be split into
separate s_waitcnt
vmcnt(0), s_waitcnt
vscnt(0) and s_waitcnt
lgkmcnt(0) to allow
them to be
independently moved
according to the
following rules.</p></li>
<li><p>s_waitcnt vmcnt(0)
must happen after
any preceding
global/generic
load/load atomic
atomicrmw-with-return-value.</p></li>
<li><p>s_waitcnt vscnt(0)
must happen after
any preceding
global/generic
store/store atomic/
atomicrmw-no-return-value.</p></li>
<li><p>s_waitcnt lgkmcnt(0)
must happen after
any preceding
local/generic
load/store/load
atomic/store
atomic/atomicrmw.</p></li>
<li><p>Must happen before
the following
atomicrmw.</p></li>
<li><p>Ensures that all
memory operations
have
completed before
performing the
atomicrmw that is
being released.</p></li>
</ul>
</div></blockquote>
<ol class="arabic simple" start="2">
<li><p>flat_atomic</p></li>
<li><p>s_waitcnt vm/vscnt(0) &amp;
lgkmcnt(0)</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>If OpenCL, omit
lgkmcnt(0).</p></li>
<li><p>Use vmcnt if atomic with
return and vscnt if atomic
with no-return.</p></li>
<li><p>Must happen before
following
buffer_gl*_inv.</p></li>
<li><p>Ensures the
atomicrmw has
completed before
invalidating the
caches.</p></li>
</ul>
</div></blockquote>
<ol class="arabic simple" start="4">
<li><p>buffer_gl0_inv;
buffer_gl1_inv</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>Must happen before
any following
global/generic
load/load
atomic/atomicrmw.</p></li>
<li><p>Ensures that
following loads
will not see stale
global data.</p></li>
</ul>
</div></blockquote>
</td>
</tr>
<tr class="row-odd"><td><p>fence</p></td>
<td><p>acq_rel</p></td>
<td><ul class="simple">
<li><p>singlethread</p></li>
<li><p>wavefront</p></li>
</ul>
</td>
<td><p><em>none</em></p></td>
<td><p><em>none</em></p></td>
<td><p><em>none</em></p></td>
</tr>
<tr class="row-even"><td><p>fence</p></td>
<td><p>acq_rel</p></td>
<td><ul class="simple">
<li><p>workgroup</p></li>
</ul>
</td>
<td><p><em>none</em></p></td>
<td><ol class="arabic simple">
<li><p>s_waitcnt lgkmcnt(0)</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>If OpenCL and
address space is
not generic, omit.</p></li>
<li><p>However,
since LLVM
currently has no
address space on
the fence need to
conservatively
always generate
(see comment for
previous fence).</p></li>
<li><p>Must happen after
any preceding
local/generic
load/load
atomic/store/store
atomic/atomicrmw.</p></li>
<li><p>Must happen before
any following
global/generic
load/load
atomic/store/store
atomic/atomicrmw.</p></li>
<li><p>Ensures that all
memory operations
to local have
completed before
performing any
following global
memory operations.</p></li>
<li><p>Ensures that the
preceding
local/generic load
atomic/atomicrmw
with an equal or
wider sync scope
and memory ordering
stronger than
unordered (this is
termed the
acquire-fence-paired-atomic
) has completed
before following
global memory
operations. This
satisfies the
requirements of
acquire.</p></li>
<li><p>Ensures that all
previous memory
operations have
completed before a
following
local/generic store
atomic/atomicrmw
with an equal or
wider sync scope
and memory ordering
stronger than
unordered (this is
termed the
release-fence-paired-atomic
). This satisfies the
requirements of
release.</p></li>
</ul>
</div></blockquote>
</td>
<td><ol class="arabic simple">
<li><p>s_waitcnt lgkmcnt(0) &amp;
vmcnt(0) &amp; vscnt(0)</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>If CU wavefront execution mode, omit vmcnt and
vscnt.</p></li>
<li><p>If OpenCL and
address space is
not generic, omit
lgkmcnt(0).</p></li>
<li><p>If OpenCL and
address space is
local, omit
vmcnt(0) and vscnt(0).</p></li>
<li><p>However,
since LLVM
currently has no
address space on
the fence need to
conservatively
always generate
(see comment for
previous fence).</p></li>
<li><p>Could be split into
separate s_waitcnt
vmcnt(0), s_waitcnt
vscnt(0) and s_waitcnt
lgkmcnt(0) to allow
them to be
independently moved
according to the
following rules.</p></li>
<li><p>s_waitcnt vmcnt(0)
must happen after
any preceding
global/generic
load/load
atomic/
atomicrmw-with-return-value.</p></li>
<li><p>s_waitcnt vscnt(0)
must happen after
any preceding
global/generic
store/store atomic/
atomicrmw-no-return-value.</p></li>
<li><p>s_waitcnt lgkmcnt(0)
must happen after
any preceding
local/generic
load/store/load
atomic/store atomic/
atomicrmw.</p></li>
<li><p>Must happen before
any following
global/generic
load/load
atomic/store/store
atomic/atomicrmw.</p></li>
<li><p>Ensures that all
memory operations
have
completed before
performing any
following global
memory operations.</p></li>
<li><p>Ensures that the
preceding
local/generic load
atomic/atomicrmw
with an equal or
wider sync scope
and memory ordering
stronger than
unordered (this is
termed the
acquire-fence-paired-atomic
) has completed
before following
global memory
operations. This
satisfies the
requirements of
acquire.</p></li>
<li><p>Ensures that all
previous memory
operations have
completed before a
following
local/generic store
atomic/atomicrmw
with an equal or
wider sync scope
and memory ordering
stronger than
unordered (this is
termed the
release-fence-paired-atomic
). This satisfies the
requirements of
release.</p></li>
<li><p>Must happen before
the following
buffer_gl0_inv.</p></li>
<li><p>Ensures that the
acquire-fence-paired
atomic has completed
before invalidating
the
cache. Therefore
any following
locations read must
be no older than
the value read by
the
acquire-fence-paired-atomic.</p></li>
</ul>
</div></blockquote>
<ol class="arabic simple" start="3">
<li><p>buffer_gl0_inv</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>If CU wavefront execution mode, omit.</p></li>
<li><p>Ensures that
following
loads will not see
stale data.</p></li>
</ul>
</div></blockquote>
</td>
</tr>
<tr class="row-odd"><td><p>fence</p></td>
<td><p>acq_rel</p></td>
<td><ul class="simple">
<li><p>agent</p></li>
<li><p>system</p></li>
</ul>
</td>
<td><p><em>none</em></p></td>
<td><ol class="arabic simple">
<li><p>s_waitcnt lgkmcnt(0) &amp;
vmcnt(0)</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>If OpenCL and
address space is
not generic, omit
lgkmcnt(0).</p></li>
<li><p>However, since LLVM
currently has no
address space on
the fence need to
conservatively
always generate
(see comment for
previous fence).</p></li>
<li><p>Could be split into
separate s_waitcnt
vmcnt(0) and
s_waitcnt
lgkmcnt(0) to allow
them to be
independently moved
according to the
following rules.</p></li>
<li><p>s_waitcnt vmcnt(0)
must happen after
any preceding
global/generic
load/store/load
atomic/store
atomic/atomicrmw.</p></li>
<li><p>s_waitcnt lgkmcnt(0)
must happen after
any preceding
local/generic
load/store/load
atomic/store
atomic/atomicrmw.</p></li>
<li><p>Must happen before
the following
buffer_wbinvl1_vol.</p></li>
<li><p>Ensures that the
preceding
global/local/generic
load
atomic/atomicrmw
with an equal or
wider sync scope
and memory ordering
stronger than
unordered (this is
termed the
acquire-fence-paired-atomic
) has completed
before invalidating
the cache. This
satisfies the
requirements of
acquire.</p></li>
<li><p>Ensures that all
previous memory
operations have
completed before a
following
global/local/generic
store
atomic/atomicrmw
with an equal or
wider sync scope
and memory ordering
stronger than
unordered (this is
termed the
release-fence-paired-atomic
). This satisfies the
requirements of
release.</p></li>
</ul>
</div></blockquote>
<ol class="arabic simple" start="2">
<li><p>buffer_wbinvl1_vol</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>Must happen before
any following
global/generic
load/load
atomic/store/store
atomic/atomicrmw.</p></li>
<li><p>Ensures that
following loads
will not see stale
global data. This
satisfies the
requirements of
acquire.</p></li>
</ul>
</div></blockquote>
</td>
<td><ol class="arabic simple">
<li><p>s_waitcnt lgkmcnt(0) &amp;
vmcnt(0) &amp; vscnt(0)</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>If OpenCL and
address space is
not generic, omit
lgkmcnt(0).</p></li>
<li><p>If OpenCL and
address space is
local, omit
vmcnt(0) and vscnt(0).</p></li>
<li><p>However, since LLVM
currently has no
address space on
the fence need to
conservatively
always generate
(see comment for
previous fence).</p></li>
<li><p>Could be split into
separate s_waitcnt
vmcnt(0), s_waitcnt
vscnt(0) and s_waitcnt
lgkmcnt(0) to allow
them to be
independently moved
according to the
following rules.</p></li>
<li><p>s_waitcnt vmcnt(0)
must happen after
any preceding
global/generic
load/load
atomic/
atomicrmw-with-return-value.</p></li>
<li><p>s_waitcnt vscnt(0)
must happen after
any preceding
global/generic
store/store atomic/
atomicrmw-no-return-value.</p></li>
<li><p>s_waitcnt lgkmcnt(0)
must happen after
any preceding
local/generic
load/store/load
atomic/store
atomic/atomicrmw.</p></li>
<li><p>Must happen before
the following
buffer_gl*_inv.</p></li>
<li><p>Ensures that the
preceding
global/local/generic
load
atomic/atomicrmw
with an equal or
wider sync scope
and memory ordering
stronger than
unordered (this is
termed the
acquire-fence-paired-atomic
) has completed
before invalidating
the caches. This
satisfies the
requirements of
acquire.</p></li>
<li><p>Ensures that all
previous memory
operations have
completed before a
following
global/local/generic
store
atomic/atomicrmw
with an equal or
wider sync scope
and memory ordering
stronger than
unordered (this is
termed the
release-fence-paired-atomic
). This satisfies the
requirements of
release.</p></li>
</ul>
</div></blockquote>
<ol class="arabic simple" start="2">
<li><p>buffer_gl0_inv;
buffer_gl1_inv</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>Must happen before
any following
global/generic
load/load
atomic/store/store
atomic/atomicrmw.</p></li>
<li><p>Ensures that
following loads
will not see stale
global data. This
satisfies the
requirements of
acquire.</p></li>
</ul>
</div></blockquote>
</td>
</tr>
<tr class="row-even"><td colspan="6"><p><strong>Sequential Consistent Atomic</strong></p></td>
</tr>
<tr class="row-odd"><td><p>load atomic</p></td>
<td><p>seq_cst</p></td>
<td><ul class="simple">
<li><p>singlethread</p></li>
<li><p>wavefront</p></li>
</ul>
</td>
<td><ul class="simple">
<li><p>global</p></li>
<li><p>local</p></li>
<li><p>generic</p></li>
</ul>
</td>
<td><p><em>Same as corresponding
load atomic acquire,
except must generated
all instructions even
for OpenCL.</em></p></td>
<td><p><em>Same as corresponding
load atomic acquire,
except must generated
all instructions even
for OpenCL.</em></p></td>
</tr>
<tr class="row-even"><td><p>load atomic</p></td>
<td><p>seq_cst</p></td>
<td><ul class="simple">
<li><p>workgroup</p></li>
</ul>
</td>
<td><ul class="simple">
<li><p>global</p></li>
<li><p>generic</p></li>
</ul>
</td>
<td><ol class="arabic simple">
<li><p>s_waitcnt lgkmcnt(0)</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>Must
happen after
preceding
global/generic load
atomic/store
atomic/atomicrmw
with memory
ordering of seq_cst
and with equal or
wider sync scope.
(Note that seq_cst
fences have their
own s_waitcnt
lgkmcnt(0) and so do
not need to be
considered.)</p></li>
<li><p>Ensures any
preceding
sequential
consistent local
memory instructions
have completed
before executing
this sequentially
consistent
instruction. This
prevents reordering
a seq_cst store
followed by a
seq_cst load. (Note
that seq_cst is
stronger than
acquire/release as
the reordering of
load acquire
followed by a store
release is
prevented by the
waitcnt of
the release, but
there is nothing
preventing a store
release followed by
load acquire from
competing out of
order.)</p></li>
</ul>
</div></blockquote>
<ol class="arabic simple" start="2">
<li><p><em>Following
instructions same as
corresponding load
atomic acquire,
except must generated
all instructions even
for OpenCL.</em></p></li>
</ol>
</td>
<td><ol class="arabic simple">
<li><p>s_waitcnt lgkmcnt(0) &amp;
vmcnt(0) &amp; vscnt(0)</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>If CU wavefront execution mode, omit vmcnt and
vscnt.</p></li>
<li><p>Could be split into
separate s_waitcnt
vmcnt(0), s_waitcnt
vscnt(0) and s_waitcnt
lgkmcnt(0) to allow
them to be
independently moved
according to the
following rules.</p></li>
<li><p>waitcnt lgkmcnt(0) must
happen after
preceding
local load
atomic/store
atomic/atomicrmw
with memory
ordering of seq_cst
and with equal or
wider sync scope.
(Note that seq_cst
fences have their
own s_waitcnt
lgkmcnt(0) and so do
not need to be
considered.)</p></li>
<li><p>waitcnt vmcnt(0)
Must happen after
preceding
global/generic load
atomic/
atomicrmw-with-return-value
with memory
ordering of seq_cst
and with equal or
wider sync scope.
(Note that seq_cst
fences have their
own s_waitcnt
vmcnt(0) and so do
not need to be
considered.)</p></li>
<li><p>waitcnt vscnt(0)
Must happen after
preceding
global/generic store
atomic/
atomicrmw-no-return-value
with memory
ordering of seq_cst
and with equal or
wider sync scope.
(Note that seq_cst
fences have their
own s_waitcnt
vscnt(0) and so do
not need to be
considered.)</p></li>
<li><p>Ensures any
preceding
sequential
consistent global/local
memory instructions
have completed
before executing
this sequentially
consistent
instruction. This
prevents reordering
a seq_cst store
followed by a
seq_cst load. (Note
that seq_cst is
stronger than
acquire/release as
the reordering of
load acquire
followed by a store
release is
prevented by the
waitcnt of
the release, but
there is nothing
preventing a store
release followed by
load acquire from
competing out of
order.)</p></li>
</ul>
</div></blockquote>
<ol class="arabic simple" start="2">
<li><p><em>Following
instructions same as
corresponding load
atomic acquire,
except must generated
all instructions even
for OpenCL.</em></p></li>
</ol>
</td>
</tr>
<tr class="row-odd"><td><p>load atomic</p></td>
<td><p>seq_cst</p></td>
<td><ul class="simple">
<li><p>workgroup</p></li>
</ul>
</td>
<td><ul class="simple">
<li><p>local</p></li>
</ul>
</td>
<td><p><em>Same as corresponding
load atomic acquire,
except must generated
all instructions even
for OpenCL.</em></p></td>
<td><ol class="arabic simple">
<li><p>s_waitcnt vmcnt(0) &amp; vscnt(0)</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>If CU wavefront execution mode, omit.</p></li>
<li><p>Could be split into
separate s_waitcnt
vmcnt(0) and s_waitcnt
vscnt(0) to allow
them to be
independently moved
according to the
following rules.</p></li>
<li><p>waitcnt vmcnt(0)
Must happen after
preceding
global/generic load
atomic/
atomicrmw-with-return-value
with memory
ordering of seq_cst
and with equal or
wider sync scope.
(Note that seq_cst
fences have their
own s_waitcnt
vmcnt(0) and so do
not need to be
considered.)</p></li>
<li><p>waitcnt vscnt(0)
Must happen after
preceding
global/generic store
atomic/
atomicrmw-no-return-value
with memory
ordering of seq_cst
and with equal or
wider sync scope.
(Note that seq_cst
fences have their
own s_waitcnt
vscnt(0) and so do
not need to be
considered.)</p></li>
<li><p>Ensures any
preceding
sequential
consistent global
memory instructions
have completed
before executing
this sequentially
consistent
instruction. This
prevents reordering
a seq_cst store
followed by a
seq_cst load. (Note
that seq_cst is
stronger than
acquire/release as
the reordering of
load acquire
followed by a store
release is
prevented by the
waitcnt of
the release, but
there is nothing
preventing a store
release followed by
load acquire from
competing out of
order.)</p></li>
</ul>
</div></blockquote>
<ol class="arabic simple" start="2">
<li><p><em>Following
instructions same as
corresponding load
atomic acquire,
except must generated
all instructions even
for OpenCL.</em></p></li>
</ol>
</td>
</tr>
<tr class="row-even"><td><p>load atomic</p></td>
<td><p>seq_cst</p></td>
<td><ul class="simple">
<li><p>agent</p></li>
<li><p>system</p></li>
</ul>
</td>
<td><ul class="simple">
<li><p>global</p></li>
<li><p>generic</p></li>
</ul>
</td>
<td><ol class="arabic simple">
<li><p>s_waitcnt lgkmcnt(0) &amp;
vmcnt(0)</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>Could be split into
separate s_waitcnt
vmcnt(0)
and s_waitcnt
lgkmcnt(0) to allow
them to be
independently moved
according to the
following rules.</p></li>
<li><p>waitcnt lgkmcnt(0)
must happen after
preceding
global/generic load
atomic/store
atomic/atomicrmw
with memory
ordering of seq_cst
and with equal or
wider sync scope.
(Note that seq_cst
fences have their
own s_waitcnt
lgkmcnt(0) and so do
not need to be
considered.)</p></li>
<li><p>waitcnt vmcnt(0)
must happen after
preceding
global/generic load
atomic/store
atomic/atomicrmw
with memory
ordering of seq_cst
and with equal or
wider sync scope.
(Note that seq_cst
fences have their
own s_waitcnt
vmcnt(0) and so do
not need to be
considered.)</p></li>
<li><p>Ensures any
preceding
sequential
consistent global
memory instructions
have completed
before executing
this sequentially
consistent
instruction. This
prevents reordering
a seq_cst store
followed by a
seq_cst load. (Note
that seq_cst is
stronger than
acquire/release as
the reordering of
load acquire
followed by a store
release is
prevented by the
waitcnt of
the release, but
there is nothing
preventing a store
release followed by
load acquire from
competing out of
order.)</p></li>
</ul>
</div></blockquote>
<ol class="arabic simple" start="2">
<li><p><em>Following
instructions same as
corresponding load
atomic acquire,
except must generated
all instructions even
for OpenCL.</em></p></li>
</ol>
</td>
<td><ol class="arabic simple">
<li><p>s_waitcnt lgkmcnt(0) &amp;
vmcnt(0) &amp; vscnt(0)</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>Could be split into
separate s_waitcnt
vmcnt(0), s_waitcnt
vscnt(0) and s_waitcnt
lgkmcnt(0) to allow
them to be
independently moved
according to the
following rules.</p></li>
<li><p>waitcnt lgkmcnt(0)
must happen after
preceding
local load
atomic/store
atomic/atomicrmw
with memory
ordering of seq_cst
and with equal or
wider sync scope.
(Note that seq_cst
fences have their
own s_waitcnt
lgkmcnt(0) and so do
not need to be
considered.)</p></li>
<li><p>waitcnt vmcnt(0)
must happen after
preceding
global/generic load
atomic/
atomicrmw-with-return-value
with memory
ordering of seq_cst
and with equal or
wider sync scope.
(Note that seq_cst
fences have their
own s_waitcnt
vmcnt(0) and so do
not need to be
considered.)</p></li>
<li><p>waitcnt vscnt(0)
Must happen after
preceding
global/generic store
atomic/
atomicrmw-no-return-value
with memory
ordering of seq_cst
and with equal or
wider sync scope.
(Note that seq_cst
fences have their
own s_waitcnt
vscnt(0) and so do
not need to be
considered.)</p></li>
<li><p>Ensures any
preceding
sequential
consistent global
memory instructions
have completed
before executing
this sequentially
consistent
instruction. This
prevents reordering
a seq_cst store
followed by a
seq_cst load. (Note
that seq_cst is
stronger than
acquire/release as
the reordering of
load acquire
followed by a store
release is
prevented by the
waitcnt of
the release, but
there is nothing
preventing a store
release followed by
load acquire from
competing out of
order.)</p></li>
</ul>
</div></blockquote>
<ol class="arabic simple" start="2">
<li><p><em>Following
instructions same as
corresponding load
atomic acquire,
except must generated
all instructions even
for OpenCL.</em></p></li>
</ol>
</td>
</tr>
<tr class="row-odd"><td><p>store atomic</p></td>
<td><p>seq_cst</p></td>
<td><ul class="simple">
<li><p>singlethread</p></li>
<li><p>wavefront</p></li>
<li><p>workgroup</p></li>
</ul>
</td>
<td><ul class="simple">
<li><p>global</p></li>
<li><p>local</p></li>
<li><p>generic</p></li>
</ul>
</td>
<td><p><em>Same as corresponding
store atomic release,
except must generated
all instructions even
for OpenCL.</em></p></td>
<td><p><em>Same as corresponding
store atomic release,
except must generated
all instructions even
for OpenCL.</em></p></td>
</tr>
<tr class="row-even"><td><p>store atomic</p></td>
<td><p>seq_cst</p></td>
<td><ul class="simple">
<li><p>agent</p></li>
<li><p>system</p></li>
</ul>
</td>
<td><ul class="simple">
<li><p>global</p></li>
<li><p>generic</p></li>
</ul>
</td>
<td><p><em>Same as corresponding
store atomic release,
except must generated
all instructions even
for OpenCL.</em></p></td>
<td><p><em>Same as corresponding
store atomic release,
except must generated
all instructions even
for OpenCL.</em></p></td>
</tr>
<tr class="row-odd"><td><p>atomicrmw</p></td>
<td><p>seq_cst</p></td>
<td><ul class="simple">
<li><p>singlethread</p></li>
<li><p>wavefront</p></li>
<li><p>workgroup</p></li>
</ul>
</td>
<td><ul class="simple">
<li><p>global</p></li>
<li><p>local</p></li>
<li><p>generic</p></li>
</ul>
</td>
<td><p><em>Same as corresponding
atomicrmw acq_rel,
except must generated
all instructions even
for OpenCL.</em></p></td>
<td><p><em>Same as corresponding
atomicrmw acq_rel,
except must generated
all instructions even
for OpenCL.</em></p></td>
</tr>
<tr class="row-even"><td><p>atomicrmw</p></td>
<td><p>seq_cst</p></td>
<td><ul class="simple">
<li><p>agent</p></li>
<li><p>system</p></li>
</ul>
</td>
<td><ul class="simple">
<li><p>global</p></li>
<li><p>generic</p></li>
</ul>
</td>
<td><p><em>Same as corresponding
atomicrmw acq_rel,
except must generated
all instructions even
for OpenCL.</em></p></td>
<td><p><em>Same as corresponding
atomicrmw acq_rel,
except must generated
all instructions even
for OpenCL.</em></p></td>
</tr>
<tr class="row-odd"><td><p>fence</p></td>
<td><p>seq_cst</p></td>
<td><ul class="simple">
<li><p>singlethread</p></li>
<li><p>wavefront</p></li>
<li><p>workgroup</p></li>
<li><p>agent</p></li>
<li><p>system</p></li>
</ul>
</td>
<td><p><em>none</em></p></td>
<td><p><em>Same as corresponding
fence acq_rel,
except must generated
all instructions even
for OpenCL.</em></p></td>
<td><p><em>Same as corresponding
fence acq_rel,
except must generated
all instructions even
for OpenCL.</em></p></td>
</tr>
</tbody>
</table>
</div></blockquote>
<p>The memory order also adds the single thread optimization constrains defined in
table
<a class="reference internal" href="#amdgpu-amdhsa-memory-model-single-thread-optimization-constraints-gfx6-gfx10-table"><span class="std std-ref">AMDHSA Memory Model Single Thread Optimization Constraints GFX6-GFX10</span></a>.</p>
<blockquote>
<div><table class="docutils align-default" id="amdgpu-amdhsa-memory-model-single-thread-optimization-constraints-gfx6-gfx10-table">
<caption><span class="caption-text">AMDHSA Memory Model Single Thread Optimization Constraints GFX6-GFX10</span><a class="headerlink" href="#amdgpu-amdhsa-memory-model-single-thread-optimization-constraints-gfx6-gfx10-table" title="Permalink to this table">¶</a></caption>
<colgroup>
<col style="width: 16%" />
<col style="width: 84%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>LLVM Memory</p></th>
<th class="head"><p>Optimization Constraints</p></th>
</tr>
<tr class="row-even"><th class="head"><p>Ordering</p></th>
<th class="head"></th>
</tr>
</thead>
<tbody>
<tr class="row-odd"><td><p>unordered</p></td>
<td><p><em>none</em></p></td>
</tr>
<tr class="row-even"><td><p>monotonic</p></td>
<td><p><em>none</em></p></td>
</tr>
<tr class="row-odd"><td><p>acquire</p></td>
<td><ul class="simple">
<li><p>If a load atomic/atomicrmw then no following load/load
atomic/store/ store atomic/atomicrmw/fence instruction can
be moved before the acquire.</p></li>
<li><p>If a fence then same as load atomic, plus no preceding
associated fence-paired-atomic can be moved after the fence.</p></li>
</ul>
</td>
</tr>
<tr class="row-even"><td><p>release</p></td>
<td><ul class="simple">
<li><p>If a store atomic/atomicrmw then no preceding load/load
atomic/store/ store atomic/atomicrmw/fence instruction can
be moved after the release.</p></li>
<li><p>If a fence then same as store atomic, plus no following
associated fence-paired-atomic can be moved before the
fence.</p></li>
</ul>
</td>
</tr>
<tr class="row-odd"><td><p>acq_rel</p></td>
<td><p>Same constraints as both acquire and release.</p></td>
</tr>
<tr class="row-even"><td><p>seq_cst</p></td>
<td><ul class="simple">
<li><p>If a load atomic then same constraints as acquire, plus no
preceding sequentially consistent load atomic/store
atomic/atomicrmw/fence instruction can be moved after the
seq_cst.</p></li>
<li><p>If a store atomic then the same constraints as release, plus
no following sequentially consistent load atomic/store
atomic/atomicrmw/fence instruction can be moved before the
seq_cst.</p></li>
<li><p>If an atomicrmw/fence then same constraints as acq_rel.</p></li>
</ul>
</td>
</tr>
</tbody>
</table>
</div></blockquote>
</div>
<div class="section" id="trap-handler-abi">
<h4><a class="toc-backref" href="#id87">Trap Handler ABI</a><a class="headerlink" href="#trap-handler-abi" title="Permalink to this headline">¶</a></h4>
<p>For code objects generated by AMDGPU backend for HSA <a class="reference internal" href="#hsa" id="id37"><span>[HSA]</span></a> compatible runtimes
(such as ROCm <a class="reference internal" href="#amd-rocm" id="id38"><span>[AMD-ROCm]</span></a>), the runtime installs a trap handler that supports
the <code class="docutils literal notranslate"><span class="pre">s_trap</span></code> instruction with the following usage:</p>
<blockquote>
<div><table class="docutils align-default" id="amdgpu-trap-handler-for-amdhsa-os-table">
<caption><span class="caption-text">AMDGPU Trap Handler for AMDHSA OS</span><a class="headerlink" href="#amdgpu-trap-handler-for-amdhsa-os-table" title="Permalink to this table">¶</a></caption>
<colgroup>
<col style="width: 26%" />
<col style="width: 21%" />
<col style="width: 21%" />
<col style="width: 32%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>Usage</p></th>
<th class="head"><p>Code Sequence</p></th>
<th class="head"><p>Trap Handler
Inputs</p></th>
<th class="head"><p>Description</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>reserved</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">s_trap</span> <span class="pre">0x00</span></code></p></td>
<td></td>
<td><p>Reserved by hardware.</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">debugtrap(arg)</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">s_trap</span> <span class="pre">0x01</span></code></p></td>
<td><dl class="simple">
<dt><code class="docutils literal notranslate"><span class="pre">SGPR0-1</span></code>:</dt><dd><p><code class="docutils literal notranslate"><span class="pre">queue_ptr</span></code></p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">VGPR0</span></code>:</dt><dd><p><code class="docutils literal notranslate"><span class="pre">arg</span></code></p>
</dd>
</dl>
</td>
<td><p>Reserved for HSA
<code class="docutils literal notranslate"><span class="pre">debugtrap</span></code>
intrinsic (not
implemented).</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">llvm.trap</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">s_trap</span> <span class="pre">0x02</span></code></p></td>
<td><dl class="simple">
<dt><code class="docutils literal notranslate"><span class="pre">SGPR0-1</span></code>:</dt><dd><p><code class="docutils literal notranslate"><span class="pre">queue_ptr</span></code></p>
</dd>
</dl>
</td>
<td><p>Causes dispatch to be
terminated and its
associated queue put
into the error state.</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">llvm.debugtrap</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">s_trap</span> <span class="pre">0x03</span></code></p></td>
<td></td>
<td><ul class="simple">
<li><p>If debugger not
installed then
behaves as a
no-operation. The
trap handler is
entered and
immediately returns
to continue
execution of the
wavefront.</p></li>
<li><p>If the debugger is
installed, causes
the debug trap to be
reported by the
debugger and the
wavefront is put in
the halt state until
resumed by the
debugger.</p></li>
</ul>
</td>
</tr>
<tr class="row-even"><td><p>reserved</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">s_trap</span> <span class="pre">0x04</span></code></p></td>
<td></td>
<td><p>Reserved.</p></td>
</tr>
<tr class="row-odd"><td><p>reserved</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">s_trap</span> <span class="pre">0x05</span></code></p></td>
<td></td>
<td><p>Reserved.</p></td>
</tr>
<tr class="row-even"><td><p>reserved</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">s_trap</span> <span class="pre">0x06</span></code></p></td>
<td></td>
<td><p>Reserved.</p></td>
</tr>
<tr class="row-odd"><td><p>debugger breakpoint</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">s_trap</span> <span class="pre">0x07</span></code></p></td>
<td></td>
<td><p>Reserved for debugger
breakpoints.</p></td>
</tr>
<tr class="row-even"><td><p>reserved</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">s_trap</span> <span class="pre">0x08</span></code></p></td>
<td></td>
<td><p>Reserved.</p></td>
</tr>
<tr class="row-odd"><td><p>reserved</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">s_trap</span> <span class="pre">0xfe</span></code></p></td>
<td></td>
<td><p>Reserved.</p></td>
</tr>
<tr class="row-even"><td><p>reserved</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">s_trap</span> <span class="pre">0xff</span></code></p></td>
<td></td>
<td><p>Reserved.</p></td>
</tr>
</tbody>
</table>
</div></blockquote>
</div>
</div>
<div class="section" id="amdpal">
<h3><a class="toc-backref" href="#id88">AMDPAL</a><a class="headerlink" href="#amdpal" title="Permalink to this headline">¶</a></h3>
<p>This section provides code conventions used when the target triple OS is
<code class="docutils literal notranslate"><span class="pre">amdpal</span></code> (see <a class="reference internal" href="#amdgpu-target-triples"><span class="std std-ref">Target Triples</span></a>) for passing runtime parameters
from the application/runtime to each invocation of a hardware shader. These
parameters include both generic, application-controlled parameters called
<em>user data</em> as well as system-generated parameters that are a product of the
draw or dispatch execution.</p>
<div class="section" id="user-data">
<h4><a class="toc-backref" href="#id89">User Data</a><a class="headerlink" href="#user-data" title="Permalink to this headline">¶</a></h4>
<p>Each hardware stage has a set of 32-bit <em>user data registers</em> which can be
written from a command buffer and then loaded into SGPRs when waves are launched
via a subsequent dispatch or draw operation. This is the way most arguments are
passed from the application/runtime to a hardware shader.</p>
</div>
<div class="section" id="compute-user-data">
<h4><a class="toc-backref" href="#id90">Compute User Data</a><a class="headerlink" href="#compute-user-data" title="Permalink to this headline">¶</a></h4>
<p>Compute shader user data mappings are simpler than graphics shaders, and have a
fixed mapping.</p>
<p>Note that there are always 10 available <em>user data entries</em> in registers -
entries beyond that limit must be fetched from memory (via the spill table
pointer) by the shader.</p>
<blockquote>
<div><table class="docutils align-default" id="pal-compute-user-data-registers">
<caption><span class="caption-text">PAL Compute Shader User Data Registers</span><a class="headerlink" href="#pal-compute-user-data-registers" title="Permalink to this table">¶</a></caption>
<colgroup>
<col style="width: 20%" />
<col style="width: 80%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>User Register</p></th>
<th class="head"><p>Description</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>0</p></td>
<td><p>Global Internal Table (32-bit pointer)</p></td>
</tr>
<tr class="row-odd"><td><p>1</p></td>
<td><p>Per-Shader Internal Table (32-bit pointer)</p></td>
</tr>
<tr class="row-even"><td><p>2 - 11</p></td>
<td><p>Application-Controlled User Data (10 32-bit values)</p></td>
</tr>
<tr class="row-odd"><td><p>12</p></td>
<td><p>Spill Table (32-bit pointer)</p></td>
</tr>
<tr class="row-even"><td><p>13 - 14</p></td>
<td><p>Thread Group Count (64-bit pointer)</p></td>
</tr>
<tr class="row-odd"><td><p>15</p></td>
<td><p>GDS Range</p></td>
</tr>
</tbody>
</table>
</div></blockquote>
</div>
<div class="section" id="graphics-user-data">
<h4><a class="toc-backref" href="#id91">Graphics User Data</a><a class="headerlink" href="#graphics-user-data" title="Permalink to this headline">¶</a></h4>
<p>Graphics pipelines support a much more flexible user data mapping:</p>
<blockquote>
<div><table class="docutils align-default" id="pal-graphics-user-data-registers">
<caption><span class="caption-text">PAL Graphics Shader User Data Registers</span><a class="headerlink" href="#pal-graphics-user-data-registers" title="Permalink to this table">¶</a></caption>
<colgroup>
<col style="width: 23%" />
<col style="width: 77%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>User Register</p></th>
<th class="head"><p>Description</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>0</p></td>
<td><p>Global Internal Table (32-bit pointer)</p></td>
</tr>
<tr class="row-odd"><td><ul class="simple">
<li></li>
</ul>
</td>
<td><p>Per-Shader Internal Table (32-bit pointer)</p></td>
</tr>
<tr class="row-even"><td><ul class="simple">
<li><p>1-15</p></li>
</ul>
</td>
<td><p>Application Controlled User Data
(1-15 Contiguous 32-bit Values in Registers)</p></td>
</tr>
<tr class="row-odd"><td><ul class="simple">
<li></li>
</ul>
</td>
<td><p>Spill Table (32-bit pointer)</p></td>
</tr>
<tr class="row-even"><td><ul class="simple">
<li></li>
</ul>
</td>
<td><p>Draw Index (First Stage Only)</p></td>
</tr>
<tr class="row-odd"><td><ul class="simple">
<li></li>
</ul>
</td>
<td><p>Vertex Offset (First Stage Only)</p></td>
</tr>
<tr class="row-even"><td><ul class="simple">
<li></li>
</ul>
</td>
<td><p>Instance Offset (First Stage Only)</p></td>
</tr>
</tbody>
</table>
<p>The placement of the global internal table remains fixed in the first <em>user
data SGPR register</em>. Otherwise all parameters are optional, and can be mapped
to any desired <em>user data SGPR register</em>, with the following regstrictions:</p>
<ul class="simple">
<li><p>Draw Index, Vertex Offset, and Instance Offset can only be used by the first
activehardware stage in a graphics pipeline (i.e. where the API vertex
shader runs).</p></li>
<li><p>Application-controlled user data must be mapped into a contiguous range of
user data registers.</p></li>
<li><p>The application-controlled user data range supports compaction remapping, so
only <em>entries</em> that are actually consumed by the shader must be assigned to
corresponding <em>registers</em>. Note that in order to support an efficient runtime
implementation, the remapping must pack <em>registers</em> in the same order as
<em>entries</em>, with unused <em>entries</em> removed.</p></li>
</ul>
</div></blockquote>
</div>
<div class="section" id="global-internal-table">
<span id="pal-global-internal-table"></span><h4><a class="toc-backref" href="#id92">Global Internal Table</a><a class="headerlink" href="#global-internal-table" title="Permalink to this headline">¶</a></h4>
<p>The global internal table is a table of <em>shader resource descriptors</em> (SRDs) that
define how certain engine-wide, runtime-managed resources should be accessed
from a shader. The majority of these resources have HW-defined formats, and it
is up to the compiler to write/read data as required by the target hardware.</p>
<p>The following table illustrates the required format:</p>
<blockquote>
<div><table class="docutils align-default" id="pal-git-table">
<caption><span class="caption-text">PAL Global Internal Table</span><a class="headerlink" href="#pal-git-table" title="Permalink to this table">¶</a></caption>
<colgroup>
<col style="width: 25%" />
<col style="width: 75%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>Offset</p></th>
<th class="head"><p>Description</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>0-3</p></td>
<td><p>Graphics Scratch SRD</p></td>
</tr>
<tr class="row-odd"><td><p>4-7</p></td>
<td><p>Compute Scratch SRD</p></td>
</tr>
<tr class="row-even"><td><p>8-11</p></td>
<td><p>ES/GS Ring Output SRD</p></td>
</tr>
<tr class="row-odd"><td><p>12-15</p></td>
<td><p>ES/GS Ring Input SRD</p></td>
</tr>
<tr class="row-even"><td><p>16-19</p></td>
<td><p>GS/VS Ring Output #0</p></td>
</tr>
<tr class="row-odd"><td><p>20-23</p></td>
<td><p>GS/VS Ring Output #1</p></td>
</tr>
<tr class="row-even"><td><p>24-27</p></td>
<td><p>GS/VS Ring Output #2</p></td>
</tr>
<tr class="row-odd"><td><p>28-31</p></td>
<td><p>GS/VS Ring Output #3</p></td>
</tr>
<tr class="row-even"><td><p>32-35</p></td>
<td><p>GS/VS Ring Input SRD</p></td>
</tr>
<tr class="row-odd"><td><p>36-39</p></td>
<td><p>Tessellation Factor Buffer SRD</p></td>
</tr>
<tr class="row-even"><td><p>40-43</p></td>
<td><p>Off-Chip LDS Buffer SRD</p></td>
</tr>
<tr class="row-odd"><td><p>44-47</p></td>
<td><p>Off-Chip Param Cache Buffer SRD</p></td>
</tr>
<tr class="row-even"><td><p>48-51</p></td>
<td><p>Sample Position Buffer SRD</p></td>
</tr>
<tr class="row-odd"><td><p>52</p></td>
<td><p>vaRange::ShadowDescriptorTable High Bits</p></td>
</tr>
</tbody>
</table>
<p>The pointer to the global internal table passed to the shader as user data
is a 32-bit pointer. The top 32 bits should be assumed to be the same as
the top 32 bits of the pipeline, so the shader may use the program
counter’s top 32 bits.</p>
</div></blockquote>
</div>
</div>
<div class="section" id="unspecified-os">
<h3><a class="toc-backref" href="#id93">Unspecified OS</a><a class="headerlink" href="#unspecified-os" title="Permalink to this headline">¶</a></h3>
<p>This section provides code conventions used when the target triple OS is
empty (see <a class="reference internal" href="#amdgpu-target-triples"><span class="std std-ref">Target Triples</span></a>).</p>
<div class="section" id="id39">
<h4><a class="toc-backref" href="#id94">Trap Handler ABI</a><a class="headerlink" href="#id39" title="Permalink to this headline">¶</a></h4>
<p>For code objects generated by AMDGPU backend for non-amdhsa OS, the runtime does
not install a trap handler. The <code class="docutils literal notranslate"><span class="pre">llvm.trap</span></code> and <code class="docutils literal notranslate"><span class="pre">llvm.debugtrap</span></code>
instructions are handled as follows:</p>
<blockquote>
<div><table class="docutils align-default" id="amdgpu-trap-handler-for-non-amdhsa-os-table">
<caption><span class="caption-text">AMDGPU Trap Handler for Non-AMDHSA OS</span><a class="headerlink" href="#amdgpu-trap-handler-for-non-amdhsa-os-table" title="Permalink to this table">¶</a></caption>
<colgroup>
<col style="width: 21%" />
<col style="width: 21%" />
<col style="width: 59%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>Usage</p></th>
<th class="head"><p>Code Sequence</p></th>
<th class="head"><p>Description</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>llvm.trap</p></td>
<td><p>s_endpgm</p></td>
<td><p>Causes wavefront to be terminated.</p></td>
</tr>
<tr class="row-odd"><td><p>llvm.debugtrap</p></td>
<td><p><em>none</em></p></td>
<td><p>Compiler warning given that there is no
trap handler installed.</p></td>
</tr>
</tbody>
</table>
</div></blockquote>
</div>
</div>
</div>
<div class="section" id="source-languages">
<h2><a class="toc-backref" href="#id95">Source Languages</a><a class="headerlink" href="#source-languages" title="Permalink to this headline">¶</a></h2>
<div class="section" id="opencl">
<span id="amdgpu-opencl"></span><h3><a class="toc-backref" href="#id96">OpenCL</a><a class="headerlink" href="#opencl" title="Permalink to this headline">¶</a></h3>
<p>When the language is OpenCL the following differences occur:</p>
<ol class="arabic simple">
<li><p>The OpenCL memory model is used (see <a class="reference internal" href="#amdgpu-amdhsa-memory-model"><span class="std std-ref">Memory Model</span></a>).</p></li>
<li><p>The AMDGPU backend appends additional arguments to the kernel’s explicit
arguments for the AMDHSA OS (see
<a class="reference internal" href="#opencl-kernel-implicit-arguments-appended-for-amdhsa-os-table"><span class="std std-ref">OpenCL kernel implicit arguments appended for AMDHSA OS</span></a>).</p></li>
<li><p>Additional metadata is generated
(see <a class="reference internal" href="#amdgpu-amdhsa-code-object-metadata"><span class="std std-ref">Code Object Metadata</span></a>).</p></li>
</ol>
<blockquote>
<div><table class="docutils align-default" id="opencl-kernel-implicit-arguments-appended-for-amdhsa-os-table">
<caption><span class="caption-text">OpenCL kernel implicit arguments appended for AMDHSA OS</span><a class="headerlink" href="#opencl-kernel-implicit-arguments-appended-for-amdhsa-os-table" title="Permalink to this table">¶</a></caption>
<colgroup>
<col style="width: 13%" />
<col style="width: 6%" />
<col style="width: 14%" />
<col style="width: 67%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>Position</p></th>
<th class="head"><p>Byte
Size</p></th>
<th class="head"><p>Byte
Alignment</p></th>
<th class="head"><p>Description</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>1</p></td>
<td><p>8</p></td>
<td><p>8</p></td>
<td><p>OpenCL Global Offset X</p></td>
</tr>
<tr class="row-odd"><td><p>2</p></td>
<td><p>8</p></td>
<td><p>8</p></td>
<td><p>OpenCL Global Offset Y</p></td>
</tr>
<tr class="row-even"><td><p>3</p></td>
<td><p>8</p></td>
<td><p>8</p></td>
<td><p>OpenCL Global Offset Z</p></td>
</tr>
<tr class="row-odd"><td><p>4</p></td>
<td><p>8</p></td>
<td><p>8</p></td>
<td><p>OpenCL address of printf buffer</p></td>
</tr>
<tr class="row-even"><td><p>5</p></td>
<td><p>8</p></td>
<td><p>8</p></td>
<td><p>OpenCL address of virtual queue used by
enqueue_kernel.</p></td>
</tr>
<tr class="row-odd"><td><p>6</p></td>
<td><p>8</p></td>
<td><p>8</p></td>
<td><p>OpenCL address of AqlWrap struct used by
enqueue_kernel.</p></td>
</tr>
<tr class="row-even"><td><p>7</p></td>
<td><p>8</p></td>
<td><p>8</p></td>
<td><p>Pointer argument used for Multi-gird
synchronization.</p></td>
</tr>
</tbody>
</table>
</div></blockquote>
</div>
<div class="section" id="hcc">
<span id="amdgpu-hcc"></span><h3><a class="toc-backref" href="#id97">HCC</a><a class="headerlink" href="#hcc" title="Permalink to this headline">¶</a></h3>
<p>When the language is HCC the following differences occur:</p>
<ol class="arabic simple">
<li><p>The HSA memory model is used (see <a class="reference internal" href="#amdgpu-amdhsa-memory-model"><span class="std std-ref">Memory Model</span></a>).</p></li>
</ol>
</div>
<div class="section" id="assembler">
<span id="amdgpu-assembler"></span><h3><a class="toc-backref" href="#id98">Assembler</a><a class="headerlink" href="#assembler" title="Permalink to this headline">¶</a></h3>
<p>AMDGPU backend has LLVM-MC based assembler which is currently in development.
It supports AMDGCN GFX6-GFX10.</p>
<p>This section describes general syntax for instructions and operands.</p>
<div class="section" id="instructions">
<h4><a class="toc-backref" href="#id99">Instructions</a><a class="headerlink" href="#instructions" title="Permalink to this headline">¶</a></h4>
<div class="toctree-wrapper compound">
</div>
<p>An instruction has the following <a class="reference internal" href="AMDGPUInstructionSyntax.html"><span class="doc">syntax</span></a>:</p>
<blockquote>
<div><p><code class="docutils literal notranslate"><span class="pre">&lt;</span></code><em>opcode</em><code class="docutils literal notranslate"><span class="pre">&gt;</span>&#160;&#160;&#160; <span class="pre">&lt;</span></code><em>operand0</em><code class="docutils literal notranslate"><span class="pre">&gt;,</span> <span class="pre">&lt;</span></code><em>operand1</em><code class="docutils literal notranslate"><span class="pre">&gt;,...</span>&#160;&#160;&#160; <span class="pre">&lt;</span></code><em>modifier0</em><code class="docutils literal notranslate"><span class="pre">&gt;</span> <span class="pre">&lt;</span></code><em>modifier1</em><code class="docutils literal notranslate"><span class="pre">&gt;...</span></code></p>
</div></blockquote>
<p><a class="reference internal" href="AMDGPUOperandSyntax.html"><span class="doc">Operands</span></a> are normally comma-separated while
<a class="reference internal" href="AMDGPUModifierSyntax.html"><span class="doc">modifiers</span></a> are space-separated.</p>
<p>The order of <em>operands</em> and <em>modifiers</em> is fixed.
Most <em>modifiers</em> are optional and may be omitted.</p>
<p>See detailed instruction syntax description for <a class="reference internal" href="AMDGPU/AMDGPUAsmGFX7.html"><span class="doc">GFX7</span></a>,
<a class="reference internal" href="AMDGPU/AMDGPUAsmGFX8.html"><span class="doc">GFX8</span></a>, <a class="reference internal" href="AMDGPU/AMDGPUAsmGFX9.html"><span class="doc">GFX9</span></a>
and <a class="reference internal" href="AMDGPU/AMDGPUAsmGFX10.html"><span class="doc">GFX10</span></a>.</p>
<p>Note that features under development are not included in this description.</p>
<p>For more information about instructions, their semantics and supported combinations of
operands, refer to one of instruction set architecture manuals
<a class="reference internal" href="#amd-gcn-gfx6" id="id40"><span>[AMD-GCN-GFX6]</span></a>, <a class="reference internal" href="#amd-gcn-gfx7" id="id41"><span>[AMD-GCN-GFX7]</span></a>, <a class="reference internal" href="#amd-gcn-gfx8" id="id42"><span>[AMD-GCN-GFX8]</span></a>, <a class="reference internal" href="#amd-gcn-gfx9" id="id43"><span>[AMD-GCN-GFX9]</span></a> and
<a class="reference internal" href="#amd-gcn-gfx10" id="id44"><span>[AMD-GCN-GFX10]</span></a>.</p>
</div>
<div class="section" id="operands">
<h4><a class="toc-backref" href="#id100">Operands</a><a class="headerlink" href="#operands" title="Permalink to this headline">¶</a></h4>
<p>Detailed description of operands may be found <a class="reference internal" href="AMDGPUOperandSyntax.html"><span class="doc">here</span></a>.</p>
</div>
<div class="section" id="modifiers">
<h4><a class="toc-backref" href="#id101">Modifiers</a><a class="headerlink" href="#modifiers" title="Permalink to this headline">¶</a></h4>
<p>Detailed description of modifiers may be found <a class="reference internal" href="AMDGPUModifierSyntax.html"><span class="doc">here</span></a>.</p>
</div>
<div class="section" id="instruction-examples">
<h4><a class="toc-backref" href="#id102">Instruction Examples</a><a class="headerlink" href="#instruction-examples" title="Permalink to this headline">¶</a></h4>
<div class="section" id="ds">
<h5><a class="toc-backref" href="#id103">DS</a><a class="headerlink" href="#ds" title="Permalink to this headline">¶</a></h5>
<div class="highlight-nasm notranslate"><div class="highlight"><pre><span></span><span class="nf">ds_add_u32</span> <span class="nv">v2</span><span class="p">,</span> <span class="nv">v4</span> <span class="nv">offset</span><span class="p">:</span><span class="mi">16</span>
<span class="nf">ds_write_src2_b64</span> <span class="nv">v2</span> <span class="nv">offset0</span><span class="p">:</span><span class="mi">4</span> <span class="nv">offset1</span><span class="p">:</span><span class="mi">8</span>
<span class="nf">ds_cmpst_f32</span> <span class="nv">v2</span><span class="p">,</span> <span class="nv">v4</span><span class="p">,</span> <span class="nv">v6</span>
<span class="nf">ds_min_rtn_f64</span> <span class="nv">v</span><span class="p">[</span><span class="mi">8</span><span class="p">:</span><span class="mi">9</span><span class="p">],</span> <span class="nv">v2</span><span class="p">,</span> <span class="nv">v</span><span class="p">[</span><span class="mi">4</span><span class="p">:</span><span class="mi">5</span><span class="p">]</span>
</pre></div>
</div>
<p>For full list of supported instructions, refer to “LDS/GDS instructions” in ISA Manual.</p>
</div>
<div class="section" id="flat">
<h5><a class="toc-backref" href="#id104">FLAT</a><a class="headerlink" href="#flat" title="Permalink to this headline">¶</a></h5>
<div class="highlight-nasm notranslate"><div class="highlight"><pre><span></span><span class="nf">flat_load_dword</span> <span class="nv">v1</span><span class="p">,</span> <span class="nv">v</span><span class="p">[</span><span class="mi">3</span><span class="p">:</span><span class="mi">4</span><span class="p">]</span>
<span class="nf">flat_store_dwordx3</span> <span class="nv">v</span><span class="p">[</span><span class="mi">3</span><span class="p">:</span><span class="mi">4</span><span class="p">],</span> <span class="nv">v</span><span class="p">[</span><span class="mi">5</span><span class="p">:</span><span class="mi">7</span><span class="p">]</span>
<span class="nf">flat_atomic_swap</span> <span class="nv">v1</span><span class="p">,</span> <span class="nv">v</span><span class="p">[</span><span class="mi">3</span><span class="p">:</span><span class="mi">4</span><span class="p">],</span> <span class="nv">v5</span> <span class="nv">glc</span>
<span class="nf">flat_atomic_cmpswap</span> <span class="nv">v1</span><span class="p">,</span> <span class="nv">v</span><span class="p">[</span><span class="mi">3</span><span class="p">:</span><span class="mi">4</span><span class="p">],</span> <span class="nv">v</span><span class="p">[</span><span class="mi">5</span><span class="p">:</span><span class="mi">6</span><span class="p">]</span> <span class="nv">glc</span> <span class="nv">slc</span>
<span class="nf">flat_atomic_fmax_x2</span> <span class="nv">v</span><span class="p">[</span><span class="mi">1</span><span class="p">:</span><span class="mi">2</span><span class="p">],</span> <span class="nv">v</span><span class="p">[</span><span class="mi">3</span><span class="p">:</span><span class="mi">4</span><span class="p">],</span> <span class="nv">v</span><span class="p">[</span><span class="mi">5</span><span class="p">:</span><span class="mi">6</span><span class="p">]</span> <span class="nv">glc</span>
</pre></div>
</div>
<p>For full list of supported instructions, refer to “FLAT instructions” in ISA Manual.</p>
</div>
<div class="section" id="mubuf">
<h5><a class="toc-backref" href="#id105">MUBUF</a><a class="headerlink" href="#mubuf" title="Permalink to this headline">¶</a></h5>
<div class="highlight-nasm notranslate"><div class="highlight"><pre><span></span><span class="nf">buffer_load_dword</span> <span class="nv">v1</span><span class="p">,</span> <span class="nv">off</span><span class="p">,</span> <span class="nv">s</span><span class="p">[</span><span class="mi">4</span><span class="p">:</span><span class="mi">7</span><span class="p">],</span> <span class="nv">s1</span>
<span class="nf">buffer_store_dwordx4</span> <span class="nv">v</span><span class="p">[</span><span class="mi">1</span><span class="p">:</span><span class="mi">4</span><span class="p">],</span> <span class="nv">v2</span><span class="p">,</span> <span class="nv">ttmp</span><span class="p">[</span><span class="mi">4</span><span class="p">:</span><span class="mi">7</span><span class="p">],</span> <span class="nv">s1</span> <span class="nv">offen</span> <span class="nv">offset</span><span class="p">:</span><span class="mi">4</span> <span class="nv">glc</span> <span class="nv">tfe</span>
<span class="nf">buffer_store_format_xy</span> <span class="nv">v</span><span class="p">[</span><span class="mi">1</span><span class="p">:</span><span class="mi">2</span><span class="p">],</span> <span class="nv">off</span><span class="p">,</span> <span class="nv">s</span><span class="p">[</span><span class="mi">4</span><span class="p">:</span><span class="mi">7</span><span class="p">],</span> <span class="nv">s1</span>
<span class="nf">buffer_wbinvl1</span>
<span class="nf">buffer_atomic_inc</span> <span class="nv">v1</span><span class="p">,</span> <span class="nv">v2</span><span class="p">,</span> <span class="nv">s</span><span class="p">[</span><span class="mi">8</span><span class="p">:</span><span class="mi">11</span><span class="p">],</span> <span class="nv">s4</span> <span class="nv">idxen</span> <span class="nv">offset</span><span class="p">:</span><span class="mi">4</span> <span class="nv">slc</span>
</pre></div>
</div>
<p>For full list of supported instructions, refer to “MUBUF Instructions” in ISA Manual.</p>
</div>
<div class="section" id="smrd-smem">
<h5><a class="toc-backref" href="#id106">SMRD/SMEM</a><a class="headerlink" href="#smrd-smem" title="Permalink to this headline">¶</a></h5>
<div class="highlight-nasm notranslate"><div class="highlight"><pre><span></span><span class="nf">s_load_dword</span> <span class="nv">s1</span><span class="p">,</span> <span class="nv">s</span><span class="p">[</span><span class="mi">2</span><span class="p">:</span><span class="mi">3</span><span class="p">],</span> <span class="mh">0xfc</span>
<span class="nf">s_load_dwordx8</span> <span class="nv">s</span><span class="p">[</span><span class="mi">8</span><span class="p">:</span><span class="mi">15</span><span class="p">],</span> <span class="nv">s</span><span class="p">[</span><span class="mi">2</span><span class="p">:</span><span class="mi">3</span><span class="p">],</span> <span class="nv">s4</span>
<span class="nf">s_load_dwordx16</span> <span class="nv">s</span><span class="p">[</span><span class="mi">88</span><span class="p">:</span><span class="mi">103</span><span class="p">],</span> <span class="nv">s</span><span class="p">[</span><span class="mi">2</span><span class="p">:</span><span class="mi">3</span><span class="p">],</span> <span class="nv">s4</span>
<span class="nf">s_dcache_inv_vol</span>
<span class="nf">s_memtime</span> <span class="nv">s</span><span class="p">[</span><span class="mi">4</span><span class="p">:</span><span class="mi">5</span><span class="p">]</span>
</pre></div>
</div>
<p>For full list of supported instructions, refer to “Scalar Memory Operations” in ISA Manual.</p>
</div>
<div class="section" id="sop1">
<h5><a class="toc-backref" href="#id107">SOP1</a><a class="headerlink" href="#sop1" title="Permalink to this headline">¶</a></h5>
<div class="highlight-nasm notranslate"><div class="highlight"><pre><span></span><span class="nf">s_mov_b32</span> <span class="nv">s1</span><span class="p">,</span> <span class="nv">s2</span>
<span class="nf">s_mov_b64</span> <span class="nv">s</span><span class="p">[</span><span class="mi">0</span><span class="p">:</span><span class="mi">1</span><span class="p">],</span> <span class="mh">0x80000000</span>
<span class="nf">s_cmov_b32</span> <span class="nv">s1</span><span class="p">,</span> <span class="mi">200</span>
<span class="nf">s_wqm_b64</span> <span class="nv">s</span><span class="p">[</span><span class="mi">2</span><span class="p">:</span><span class="mi">3</span><span class="p">],</span> <span class="nv">s</span><span class="p">[</span><span class="mi">4</span><span class="p">:</span><span class="mi">5</span><span class="p">]</span>
<span class="nf">s_bcnt0_i32_b64</span> <span class="nv">s1</span><span class="p">,</span> <span class="nv">s</span><span class="p">[</span><span class="mi">2</span><span class="p">:</span><span class="mi">3</span><span class="p">]</span>
<span class="nf">s_swappc_b64</span> <span class="nv">s</span><span class="p">[</span><span class="mi">2</span><span class="p">:</span><span class="mi">3</span><span class="p">],</span> <span class="nv">s</span><span class="p">[</span><span class="mi">4</span><span class="p">:</span><span class="mi">5</span><span class="p">]</span>
<span class="nf">s_cbranch_join</span> <span class="nv">s</span><span class="p">[</span><span class="mi">4</span><span class="p">:</span><span class="mi">5</span><span class="p">]</span>
</pre></div>
</div>
<p>For full list of supported instructions, refer to “SOP1 Instructions” in ISA Manual.</p>
</div>
<div class="section" id="sop2">
<h5><a class="toc-backref" href="#id108">SOP2</a><a class="headerlink" href="#sop2" title="Permalink to this headline">¶</a></h5>
<div class="highlight-nasm notranslate"><div class="highlight"><pre><span></span><span class="nf">s_add_u32</span> <span class="nv">s1</span><span class="p">,</span> <span class="nv">s2</span><span class="p">,</span> <span class="nv">s3</span>
<span class="nf">s_and_b64</span> <span class="nv">s</span><span class="p">[</span><span class="mi">2</span><span class="p">:</span><span class="mi">3</span><span class="p">],</span> <span class="nv">s</span><span class="p">[</span><span class="mi">4</span><span class="p">:</span><span class="mi">5</span><span class="p">],</span> <span class="nv">s</span><span class="p">[</span><span class="mi">6</span><span class="p">:</span><span class="mi">7</span><span class="p">]</span>
<span class="nf">s_cselect_b32</span> <span class="nv">s1</span><span class="p">,</span> <span class="nv">s2</span><span class="p">,</span> <span class="nv">s3</span>
<span class="nf">s_andn2_b32</span> <span class="nv">s2</span><span class="p">,</span> <span class="nv">s4</span><span class="p">,</span> <span class="nv">s6</span>
<span class="nf">s_lshr_b64</span> <span class="nv">s</span><span class="p">[</span><span class="mi">2</span><span class="p">:</span><span class="mi">3</span><span class="p">],</span> <span class="nv">s</span><span class="p">[</span><span class="mi">4</span><span class="p">:</span><span class="mi">5</span><span class="p">],</span> <span class="nv">s6</span>
<span class="nf">s_ashr_i32</span> <span class="nv">s2</span><span class="p">,</span> <span class="nv">s4</span><span class="p">,</span> <span class="nv">s6</span>
<span class="nf">s_bfm_b64</span> <span class="nv">s</span><span class="p">[</span><span class="mi">2</span><span class="p">:</span><span class="mi">3</span><span class="p">],</span> <span class="nv">s4</span><span class="p">,</span> <span class="nv">s6</span>
<span class="nf">s_bfe_i64</span> <span class="nv">s</span><span class="p">[</span><span class="mi">2</span><span class="p">:</span><span class="mi">3</span><span class="p">],</span> <span class="nv">s</span><span class="p">[</span><span class="mi">4</span><span class="p">:</span><span class="mi">5</span><span class="p">],</span> <span class="nv">s6</span>
<span class="nf">s_cbranch_g_fork</span> <span class="nv">s</span><span class="p">[</span><span class="mi">4</span><span class="p">:</span><span class="mi">5</span><span class="p">],</span> <span class="nv">s</span><span class="p">[</span><span class="mi">6</span><span class="p">:</span><span class="mi">7</span><span class="p">]</span>
</pre></div>
</div>
<p>For full list of supported instructions, refer to “SOP2 Instructions” in ISA Manual.</p>
</div>
<div class="section" id="sopc">
<h5><a class="toc-backref" href="#id109">SOPC</a><a class="headerlink" href="#sopc" title="Permalink to this headline">¶</a></h5>
<div class="highlight-nasm notranslate"><div class="highlight"><pre><span></span><span class="nf">s_cmp_eq_i32</span> <span class="nv">s1</span><span class="p">,</span> <span class="nv">s2</span>
<span class="nf">s_bitcmp1_b32</span> <span class="nv">s1</span><span class="p">,</span> <span class="nv">s2</span>
<span class="nf">s_bitcmp0_b64</span> <span class="nv">s</span><span class="p">[</span><span class="mi">2</span><span class="p">:</span><span class="mi">3</span><span class="p">],</span> <span class="nv">s4</span>
<span class="nf">s_setvskip</span> <span class="nv">s3</span><span class="p">,</span> <span class="nv">s5</span>
</pre></div>
</div>
<p>For full list of supported instructions, refer to “SOPC Instructions” in ISA Manual.</p>
</div>
<div class="section" id="sopp">
<h5><a class="toc-backref" href="#id110">SOPP</a><a class="headerlink" href="#sopp" title="Permalink to this headline">¶</a></h5>
<div class="highlight-nasm notranslate"><div class="highlight"><pre><span></span><span class="nf">s_barrier</span>
<span class="nf">s_nop</span> <span class="mi">2</span>
<span class="nf">s_endpgm</span>
<span class="nf">s_waitcnt</span> <span class="mi">0</span> <span class="c1">; Wait for all counters to be 0</span>
<span class="nf">s_waitcnt</span> <span class="nv">vmcnt</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span> <span class="o">&amp;</span> <span class="nv">expcnt</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span> <span class="o">&amp;</span> <span class="nv">lgkmcnt</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span> <span class="c1">; Equivalent to above</span>
<span class="nf">s_waitcnt</span> <span class="nv">vmcnt</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> <span class="c1">; Wait for vmcnt counter to be 1.</span>
<span class="nf">s_sethalt</span> <span class="mi">9</span>
<span class="nf">s_sleep</span> <span class="mi">10</span>
<span class="nf">s_sendmsg</span> <span class="mh">0x1</span>
<span class="nf">s_sendmsg</span> <span class="nv">sendmsg</span><span class="p">(</span><span class="nv">MSG_INTERRUPT</span><span class="p">)</span>
<span class="nf">s_trap</span> <span class="mi">1</span>
</pre></div>
</div>
<p>For full list of supported instructions, refer to “SOPP Instructions” in ISA Manual.</p>
<p>Unless otherwise mentioned, little verification is performed on the operands
of SOPP Instructions, so it is up to the programmer to be familiar with the
range or acceptable values.</p>
</div>
<div class="section" id="valu">
<h5><a class="toc-backref" href="#id111">VALU</a><a class="headerlink" href="#valu" title="Permalink to this headline">¶</a></h5>
<p>For vector ALU instruction opcodes (VOP1, VOP2, VOP3, VOPC, VOP_DPP, VOP_SDWA),
the assembler will automatically use optimal encoding based on its operands.
To force specific encoding, one can add a suffix to the opcode of the instruction:</p>
<ul class="simple">
<li><p>_e32 for 32-bit VOP1/VOP2/VOPC</p></li>
<li><p>_e64 for 64-bit VOP3</p></li>
<li><p>_dpp for VOP_DPP</p></li>
<li><p>_sdwa for VOP_SDWA</p></li>
</ul>
<p>VOP1/VOP2/VOP3/VOPC examples:</p>
<div class="highlight-nasm notranslate"><div class="highlight"><pre><span></span><span class="nf">v_mov_b32</span> <span class="nv">v1</span><span class="p">,</span> <span class="nv">v2</span>
<span class="nf">v_mov_b32_e32</span> <span class="nv">v1</span><span class="p">,</span> <span class="nv">v2</span>
<span class="nf">v_nop</span>
<span class="nf">v_cvt_f64_i32_e32</span> <span class="nv">v</span><span class="p">[</span><span class="mi">1</span><span class="p">:</span><span class="mi">2</span><span class="p">],</span> <span class="nv">v2</span>
<span class="nf">v_floor_f32_e32</span> <span class="nv">v1</span><span class="p">,</span> <span class="nv">v2</span>
<span class="nf">v_bfrev_b32_e32</span> <span class="nv">v1</span><span class="p">,</span> <span class="nv">v2</span>
<span class="nf">v_add_f32_e32</span> <span class="nv">v1</span><span class="p">,</span> <span class="nv">v2</span><span class="p">,</span> <span class="nv">v3</span>
<span class="nf">v_mul_i32_i24_e64</span> <span class="nv">v1</span><span class="p">,</span> <span class="nv">v2</span><span class="p">,</span> <span class="mi">3</span>
<span class="nf">v_mul_i32_i24_e32</span> <span class="nv">v1</span><span class="p">,</span> <span class="o">-</span><span class="mi">3</span><span class="p">,</span> <span class="nv">v3</span>
<span class="nf">v_mul_i32_i24_e32</span> <span class="nv">v1</span><span class="p">,</span> <span class="o">-</span><span class="mi">100</span><span class="p">,</span> <span class="nv">v3</span>
<span class="nf">v_addc_u32</span> <span class="nv">v1</span><span class="p">,</span> <span class="nv">s</span><span class="p">[</span><span class="mi">0</span><span class="p">:</span><span class="mi">1</span><span class="p">],</span> <span class="nv">v2</span><span class="p">,</span> <span class="nv">v3</span><span class="p">,</span> <span class="nv">s</span><span class="p">[</span><span class="mi">2</span><span class="p">:</span><span class="mi">3</span><span class="p">]</span>
<span class="nf">v_max_f16_e32</span> <span class="nv">v1</span><span class="p">,</span> <span class="nv">v2</span><span class="p">,</span> <span class="nv">v3</span>
</pre></div>
</div>
<p>VOP_DPP examples:</p>
<div class="highlight-nasm notranslate"><div class="highlight"><pre><span></span><span class="nf">v_mov_b32</span> <span class="nv">v0</span><span class="p">,</span> <span class="nv">v0</span> <span class="nv">quad_perm</span><span class="p">:[</span><span class="mi">0</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">]</span>
<span class="nf">v_sin_f32</span> <span class="nv">v0</span><span class="p">,</span> <span class="nv">v0</span> <span class="nv">row_shl</span><span class="p">:</span><span class="mi">1</span> <span class="nv">row_mask</span><span class="p">:</span><span class="mh">0xa</span> <span class="nv">bank_mask</span><span class="p">:</span><span class="mh">0x1</span> <span class="nv">bound_ctrl</span><span class="p">:</span><span class="mi">0</span>
<span class="nf">v_mov_b32</span> <span class="nv">v0</span><span class="p">,</span> <span class="nv">v0</span> <span class="nv">wave_shl</span><span class="p">:</span><span class="mi">1</span>
<span class="nf">v_mov_b32</span> <span class="nv">v0</span><span class="p">,</span> <span class="nv">v0</span> <span class="nv">row_mirror</span>
<span class="nf">v_mov_b32</span> <span class="nv">v0</span><span class="p">,</span> <span class="nv">v0</span> <span class="nv">row_bcast</span><span class="p">:</span><span class="mi">31</span>
<span class="nf">v_mov_b32</span> <span class="nv">v0</span><span class="p">,</span> <span class="nv">v0</span> <span class="nv">quad_perm</span><span class="p">:[</span><span class="mi">1</span><span class="p">,</span><span class="mi">3</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">]</span> <span class="nv">row_mask</span><span class="p">:</span><span class="mh">0xa</span> <span class="nv">bank_mask</span><span class="p">:</span><span class="mh">0x1</span> <span class="nv">bound_ctrl</span><span class="p">:</span><span class="mi">0</span>
<span class="nf">v_add_f32</span> <span class="nv">v0</span><span class="p">,</span> <span class="nv">v0</span><span class="p">,</span> <span class="o">|</span><span class="nv">v0</span><span class="o">|</span> <span class="nv">row_shl</span><span class="p">:</span><span class="mi">1</span> <span class="nv">row_mask</span><span class="p">:</span><span class="mh">0xa</span> <span class="nv">bank_mask</span><span class="p">:</span><span class="mh">0x1</span> <span class="nv">bound_ctrl</span><span class="p">:</span><span class="mi">0</span>
<span class="nf">v_max_f16</span> <span class="nv">v1</span><span class="p">,</span> <span class="nv">v2</span><span class="p">,</span> <span class="nv">v3</span> <span class="nv">row_shl</span><span class="p">:</span><span class="mi">1</span> <span class="nv">row_mask</span><span class="p">:</span><span class="mh">0xa</span> <span class="nv">bank_mask</span><span class="p">:</span><span class="mh">0x1</span> <span class="nv">bound_ctrl</span><span class="p">:</span><span class="mi">0</span>
</pre></div>
</div>
<p>VOP_SDWA examples:</p>
<div class="highlight-nasm notranslate"><div class="highlight"><pre><span></span><span class="nf">v_mov_b32</span> <span class="nv">v1</span><span class="p">,</span> <span class="nv">v2</span> <span class="nb">ds</span><span class="nv">t_sel</span><span class="p">:</span><span class="kt">BYTE</span><span class="nv">_0</span> <span class="nb">ds</span><span class="nv">t_unused</span><span class="p">:</span><span class="nv">UNUSED_PRESERVE</span> <span class="nv">src0_sel</span><span class="p">:</span><span class="kt">DWORD</span>
<span class="nf">v_min_u32</span> <span class="nv">v200</span><span class="p">,</span> <span class="nv">v200</span><span class="p">,</span> <span class="nv">v1</span> <span class="nb">ds</span><span class="nv">t_sel</span><span class="p">:</span><span class="kt">WORD</span><span class="nv">_1</span> <span class="nb">ds</span><span class="nv">t_unused</span><span class="p">:</span><span class="nv">UNUSED_PAD</span> <span class="nv">src0_sel</span><span class="p">:</span><span class="kt">BYTE</span><span class="nv">_1</span> <span class="nv">src1_sel</span><span class="p">:</span><span class="kt">DWORD</span>
<span class="nf">v_sin_f32</span> <span class="nv">v0</span><span class="p">,</span> <span class="nv">v0</span> <span class="nb">ds</span><span class="nv">t_unused</span><span class="p">:</span><span class="nv">UNUSED_PAD</span> <span class="nv">src0_sel</span><span class="p">:</span><span class="kt">WORD</span><span class="nv">_1</span>
<span class="nf">v_fract_f32</span> <span class="nv">v0</span><span class="p">,</span> <span class="o">|</span><span class="nv">v0</span><span class="o">|</span> <span class="nb">ds</span><span class="nv">t_sel</span><span class="p">:</span><span class="kt">DWORD</span> <span class="nb">ds</span><span class="nv">t_unused</span><span class="p">:</span><span class="nv">UNUSED_PAD</span> <span class="nv">src0_sel</span><span class="p">:</span><span class="kt">WORD</span><span class="nv">_1</span>
<span class="nf">v_cmpx_le_u32</span> <span class="nv">vcc</span><span class="p">,</span> <span class="nv">v1</span><span class="p">,</span> <span class="nv">v2</span> <span class="nv">src0_sel</span><span class="p">:</span><span class="kt">BYTE</span><span class="nv">_2</span> <span class="nv">src1_sel</span><span class="p">:</span><span class="kt">WORD</span><span class="nv">_0</span>
</pre></div>
</div>
<p>For full list of supported instructions, refer to “Vector ALU instructions”.</p>
</div>
</div>
<div class="section" id="code-object-v2-predefined-symbols-mattr-code-object-v3">
<span id="amdgpu-amdhsa-assembler-predefined-symbols-v2"></span><h4><a class="toc-backref" href="#id112">Code Object V2 Predefined Symbols (-mattr=-code-object-v3)</a><a class="headerlink" href="#code-object-v2-predefined-symbols-mattr-code-object-v3" title="Permalink to this headline">¶</a></h4>
<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p>Code Object V2 is not the default code object version emitted by
this version of LLVM. For a description of the predefined symbols available
with the default configuration (Code Object V3) see
<a class="reference internal" href="#amdgpu-amdhsa-assembler-predefined-symbols-v3"><span class="std std-ref">Code Object V3 Predefined Symbols (-mattr=+code-object-v3)</span></a>.</p>
</div>
<p>The AMDGPU assembler defines and updates some symbols automatically. These
symbols do not affect code generation.</p>
<div class="section" id="option-machine-version-major">
<h5><a class="toc-backref" href="#id113">.option.machine_version_major</a><a class="headerlink" href="#option-machine-version-major" title="Permalink to this headline">¶</a></h5>
<p>Set to the GFX major generation number of the target being assembled for. For
example, when assembling for a “GFX9” target this will be set to the integer
value “9”. The possible GFX major generation numbers are presented in
<a class="reference internal" href="#amdgpu-processors"><span class="std std-ref">Processors</span></a>.</p>
</div>
<div class="section" id="option-machine-version-minor">
<h5><a class="toc-backref" href="#id114">.option.machine_version_minor</a><a class="headerlink" href="#option-machine-version-minor" title="Permalink to this headline">¶</a></h5>
<p>Set to the GFX minor generation number of the target being assembled for. For
example, when assembling for a “GFX810” target this will be set to the integer
value “1”. The possible GFX minor generation numbers are presented in
<a class="reference internal" href="#amdgpu-processors"><span class="std std-ref">Processors</span></a>.</p>
</div>
<div class="section" id="option-machine-version-stepping">
<h5><a class="toc-backref" href="#id115">.option.machine_version_stepping</a><a class="headerlink" href="#option-machine-version-stepping" title="Permalink to this headline">¶</a></h5>
<p>Set to the GFX stepping generation number of the target being assembled for.
For example, when assembling for a “GFX704” target this will be set to the
integer value “4”. The possible GFX stepping generation numbers are presented
in <a class="reference internal" href="#amdgpu-processors"><span class="std std-ref">Processors</span></a>.</p>
</div>
<div class="section" id="kernel-vgpr-count">
<h5><a class="toc-backref" href="#id116">.kernel.vgpr_count</a><a class="headerlink" href="#kernel-vgpr-count" title="Permalink to this headline">¶</a></h5>
<p>Set to zero each time a
<a class="reference internal" href="#amdgpu-amdhsa-assembler-directive-amdgpu-hsa-kernel"><span class="std std-ref">.amdgpu_hsa_kernel (name)</span></a> directive is
encountered. At each instruction, if the current value of this symbol is less
than or equal to the maximum VPGR number explicitly referenced within that
instruction then the symbol value is updated to equal that VGPR number plus
one.</p>
</div>
<div class="section" id="kernel-sgpr-count">
<h5><a class="toc-backref" href="#id117">.kernel.sgpr_count</a><a class="headerlink" href="#kernel-sgpr-count" title="Permalink to this headline">¶</a></h5>
<p>Set to zero each time a
<a class="reference internal" href="#amdgpu-amdhsa-assembler-directive-amdgpu-hsa-kernel"><span class="std std-ref">.amdgpu_hsa_kernel (name)</span></a> directive is
encountered. At each instruction, if the current value of this symbol is less
than or equal to the maximum VPGR number explicitly referenced within that
instruction then the symbol value is updated to equal that SGPR number plus
one.</p>
</div>
</div>
<div class="section" id="code-object-v2-directives-mattr-code-object-v3">
<span id="amdgpu-amdhsa-assembler-directives-v2"></span><h4><a class="toc-backref" href="#id118">Code Object V2 Directives (-mattr=-code-object-v3)</a><a class="headerlink" href="#code-object-v2-directives-mattr-code-object-v3" title="Permalink to this headline">¶</a></h4>
<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p>Code Object V2 is not the default code object version emitted by
this version of LLVM. For a description of the directives supported with
the default configuration (Code Object V3) see
<a class="reference internal" href="#amdgpu-amdhsa-assembler-directives-v3"><span class="std std-ref">Code Object V3 Directives (-mattr=+code-object-v3)</span></a>.</p>
</div>
<p>AMDGPU ABI defines auxiliary data in output code object. In assembly source,
one can specify them with assembler directives.</p>
<div class="section" id="hsa-code-object-version-major-minor">
<h5><a class="toc-backref" href="#id119">.hsa_code_object_version major, minor</a><a class="headerlink" href="#hsa-code-object-version-major-minor" title="Permalink to this headline">¶</a></h5>
<p><em>major</em> and <em>minor</em> are integers that specify the version of the HSA code
object that will be generated by the assembler.</p>
</div>
<div class="section" id="hsa-code-object-isa-major-minor-stepping-vendor-arch">
<h5><a class="toc-backref" href="#id120">.hsa_code_object_isa [major, minor, stepping, vendor, arch]</a><a class="headerlink" href="#hsa-code-object-isa-major-minor-stepping-vendor-arch" title="Permalink to this headline">¶</a></h5>
<p><em>major</em>, <em>minor</em>, and <em>stepping</em> are all integers that describe the instruction
set architecture (ISA) version of the assembly program.</p>
<p><em>vendor</em> and <em>arch</em> are quoted strings.  <em>vendor</em> should always be equal to
“AMD” and <em>arch</em> should always be equal to “AMDGPU”.</p>
<p>By default, the assembler will derive the ISA version, <em>vendor</em>, and <em>arch</em>
from the value of the -mcpu option that is passed to the assembler.</p>
</div>
<div class="section" id="amdgpu-hsa-kernel-name">
<span id="amdgpu-amdhsa-assembler-directive-amdgpu-hsa-kernel"></span><h5><a class="toc-backref" href="#id121">.amdgpu_hsa_kernel (name)</a><a class="headerlink" href="#amdgpu-hsa-kernel-name" title="Permalink to this headline">¶</a></h5>
<p>This directives specifies that the symbol with given name is a kernel entry point
(label) and the object should contain corresponding symbol of type STT_AMDGPU_HSA_KERNEL.</p>
</div>
<div class="section" id="amd-kernel-code-t">
<h5><a class="toc-backref" href="#id122">.amd_kernel_code_t</a><a class="headerlink" href="#amd-kernel-code-t" title="Permalink to this headline">¶</a></h5>
<p>This directive marks the beginning of a list of key / value pairs that are used
to specify the amd_kernel_code_t object that will be emitted by the assembler.
The list must be terminated by the <em>.end_amd_kernel_code_t</em> directive.  For
any amd_kernel_code_t values that are unspecified a default value will be
used.  The default value for all keys is 0, with the following exceptions:</p>
<ul class="simple">
<li><p><em>amd_code_version_major</em> defaults to 1.</p></li>
<li><p><em>amd_kernel_code_version_minor</em> defaults to 2.</p></li>
<li><p><em>amd_machine_kind</em> defaults to 1.</p></li>
<li><p><em>amd_machine_version_major</em>, <em>machine_version_minor</em>, and
<em>amd_machine_version_stepping</em> are derived from the value of the -mcpu option
that is passed to the assembler.</p></li>
<li><p><em>kernel_code_entry_byte_offset</em> defaults to 256.</p></li>
<li><p><em>wavefront_size</em> defaults 6 for all targets before GFX10. For GFX10 onwards
defaults to 6 if target feature <code class="docutils literal notranslate"><span class="pre">wavefrontsize64</span></code> is enabled, otherwise 5.
Note that wavefront size is specified as a power of two, so a value of <strong>n</strong>
means a size of 2^ <strong>n</strong>.</p></li>
<li><p><em>call_convention</em> defaults to -1.</p></li>
<li><p><em>kernarg_segment_alignment</em>, <em>group_segment_alignment</em>, and
<em>private_segment_alignment</em> default to 4. Note that alignments are specified
as a power of 2, so a value of <strong>n</strong> means an alignment of 2^ <strong>n</strong>.</p></li>
<li><p><em>enable_wgp_mode</em> defaults to 1 if target feature <code class="docutils literal notranslate"><span class="pre">cumode</span></code> is disabled for
GFX10 onwards.</p></li>
<li><p><em>enable_mem_ordered</em> defaults to 1 for GFX10 onwards.</p></li>
</ul>
<p>The <em>.amd_kernel_code_t</em> directive must be placed immediately after the
function label and before any instructions.</p>
<p>For a full list of amd_kernel_code_t keys, refer to AMDGPU ABI document,
comments in lib/Target/AMDGPU/AmdKernelCodeT.h and test/CodeGen/AMDGPU/hsa.s.</p>
</div>
</div>
<div class="section" id="code-object-v2-example-source-code-mattr-code-object-v3">
<span id="amdgpu-amdhsa-assembler-example-v2"></span><h4><a class="toc-backref" href="#id123">Code Object V2 Example Source Code (-mattr=-code-object-v3)</a><a class="headerlink" href="#code-object-v2-example-source-code-mattr-code-object-v3" title="Permalink to this headline">¶</a></h4>
<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p>Code Object V2 is not the default code object version emitted by
this version of LLVM. For a description of the directives supported with
the default configuration (Code Object V3) see
<a class="reference internal" href="#amdgpu-amdhsa-assembler-example-v3"><span class="std std-ref">Code Object V3 Example Source Code (-mattr=+code-object-v3)</span></a>.</p>
</div>
<p>Here is an example of a minimal assembly source file, defining one HSA kernel:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>.hsa_code_object_version 1,0
.hsa_code_object_isa

.hsatext
.globl  hello_world
.p2align 8
.amdgpu_hsa_kernel hello_world

hello_world:

   .amd_kernel_code_t
      enable_sgpr_kernarg_segment_ptr = 1
      is_ptr64 = 1
      compute_pgm_rsrc1_vgprs = 0
      compute_pgm_rsrc1_sgprs = 0
      compute_pgm_rsrc2_user_sgpr = 2
      compute_pgm_rsrc1_wgp_mode = 0
      compute_pgm_rsrc1_mem_ordered = 0
      compute_pgm_rsrc1_fwd_progress = 1
  .end_amd_kernel_code_t

  s_load_dwordx2 s[0:1], s[0:1] 0x0
  v_mov_b32 v0, 3.14159
  s_waitcnt lgkmcnt(0)
  v_mov_b32 v1, s0
  v_mov_b32 v2, s1
  flat_store_dword v[1:2], v0
  s_endpgm
.Lfunc_end0:
     .size   hello_world, .Lfunc_end0-hello_world
</pre></div>
</div>
</div>
<div class="section" id="code-object-v3-predefined-symbols-mattr-code-object-v3">
<span id="amdgpu-amdhsa-assembler-predefined-symbols-v3"></span><h4><a class="toc-backref" href="#id124">Code Object V3 Predefined Symbols (-mattr=+code-object-v3)</a><a class="headerlink" href="#code-object-v3-predefined-symbols-mattr-code-object-v3" title="Permalink to this headline">¶</a></h4>
<p>The AMDGPU assembler defines and updates some symbols automatically. These
symbols do not affect code generation.</p>
<div class="section" id="amdgcn-gfx-generation-number">
<h5><a class="toc-backref" href="#id125">.amdgcn.gfx_generation_number</a><a class="headerlink" href="#amdgcn-gfx-generation-number" title="Permalink to this headline">¶</a></h5>
<p>Set to the GFX major generation number of the target being assembled for. For
example, when assembling for a “GFX9” target this will be set to the integer
value “9”. The possible GFX major generation numbers are presented in
<a class="reference internal" href="#amdgpu-processors"><span class="std std-ref">Processors</span></a>.</p>
</div>
<div class="section" id="amdgcn-gfx-generation-minor">
<h5><a class="toc-backref" href="#id126">.amdgcn.gfx_generation_minor</a><a class="headerlink" href="#amdgcn-gfx-generation-minor" title="Permalink to this headline">¶</a></h5>
<p>Set to the GFX minor generation number of the target being assembled for. For
example, when assembling for a “GFX810” target this will be set to the integer
value “1”. The possible GFX minor generation numbers are presented in
<a class="reference internal" href="#amdgpu-processors"><span class="std std-ref">Processors</span></a>.</p>
</div>
<div class="section" id="amdgcn-gfx-generation-stepping">
<h5><a class="toc-backref" href="#id127">.amdgcn.gfx_generation_stepping</a><a class="headerlink" href="#amdgcn-gfx-generation-stepping" title="Permalink to this headline">¶</a></h5>
<p>Set to the GFX stepping generation number of the target being assembled for.
For example, when assembling for a “GFX704” target this will be set to the
integer value “4”. The possible GFX stepping generation numbers are presented
in <a class="reference internal" href="#amdgpu-processors"><span class="std std-ref">Processors</span></a>.</p>
</div>
<div class="section" id="amdgcn-next-free-vgpr">
<span id="amdgpu-amdhsa-assembler-symbol-next-free-vgpr"></span><h5><a class="toc-backref" href="#id128">.amdgcn.next_free_vgpr</a><a class="headerlink" href="#amdgcn-next-free-vgpr" title="Permalink to this headline">¶</a></h5>
<p>Set to zero before assembly begins. At each instruction, if the current value
of this symbol is less than or equal to the maximum VGPR number explicitly
referenced within that instruction then the symbol value is updated to equal
that VGPR number plus one.</p>
<p>May be used to set the <cite>.amdhsa_next_free_vpgr</cite> directive in
<a class="reference internal" href="#amdhsa-kernel-directives-table"><span class="std std-ref">AMDHSA Kernel Assembler Directives</span></a>.</p>
<p>May be set at any time, e.g. manually set to zero at the start of each kernel.</p>
</div>
<div class="section" id="amdgcn-next-free-sgpr">
<span id="amdgpu-amdhsa-assembler-symbol-next-free-sgpr"></span><h5><a class="toc-backref" href="#id129">.amdgcn.next_free_sgpr</a><a class="headerlink" href="#amdgcn-next-free-sgpr" title="Permalink to this headline">¶</a></h5>
<p>Set to zero before assembly begins. At each instruction, if the current value
of this symbol is less than or equal the maximum SGPR number explicitly
referenced within that instruction then the symbol value is updated to equal
that SGPR number plus one.</p>
<p>May be used to set the <cite>.amdhsa_next_free_spgr</cite> directive in
<a class="reference internal" href="#amdhsa-kernel-directives-table"><span class="std std-ref">AMDHSA Kernel Assembler Directives</span></a>.</p>
<p>May be set at any time, e.g. manually set to zero at the start of each kernel.</p>
</div>
</div>
<div class="section" id="code-object-v3-directives-mattr-code-object-v3">
<span id="amdgpu-amdhsa-assembler-directives-v3"></span><h4><a class="toc-backref" href="#id130">Code Object V3 Directives (-mattr=+code-object-v3)</a><a class="headerlink" href="#code-object-v3-directives-mattr-code-object-v3" title="Permalink to this headline">¶</a></h4>
<p>Directives which begin with <code class="docutils literal notranslate"><span class="pre">.amdgcn</span></code> are valid for all <code class="docutils literal notranslate"><span class="pre">amdgcn</span></code>
architecture processors, and are not OS-specific. Directives which begin with
<code class="docutils literal notranslate"><span class="pre">.amdhsa</span></code> are specific to <code class="docutils literal notranslate"><span class="pre">amdgcn</span></code> architecture processors when the
<code class="docutils literal notranslate"><span class="pre">amdhsa</span></code> OS is specified. See <a class="reference internal" href="#amdgpu-target-triples"><span class="std std-ref">Target Triples</span></a> and
<a class="reference internal" href="#amdgpu-processors"><span class="std std-ref">Processors</span></a>.</p>
<div class="section" id="amdgcn-target-target">
<h5><a class="toc-backref" href="#id131">.amdgcn_target &lt;target&gt;</a><a class="headerlink" href="#amdgcn-target-target" title="Permalink to this headline">¶</a></h5>
<p>Optional directive which declares the target supported by the containing
assembler source file. Valid values are described in
<a class="reference internal" href="#amdgpu-amdhsa-code-object-target-identification"><span class="std std-ref">Code Object Target Identification</span></a>. Used by the assembler
to validate command-line options such as <code class="docutils literal notranslate"><span class="pre">-triple</span></code>, <code class="docutils literal notranslate"><span class="pre">-mcpu</span></code>, and those
which specify target features.</p>
</div>
<div class="section" id="amdhsa-kernel-name">
<h5><a class="toc-backref" href="#id132">.amdhsa_kernel &lt;name&gt;</a><a class="headerlink" href="#amdhsa-kernel-name" title="Permalink to this headline">¶</a></h5>
<p>Creates a correctly aligned AMDHSA kernel descriptor and a symbol,
<code class="docutils literal notranslate"><span class="pre">&lt;name&gt;.kd</span></code>, in the current location of the current section. Only valid when
the OS is <code class="docutils literal notranslate"><span class="pre">amdhsa</span></code>. <code class="docutils literal notranslate"><span class="pre">&lt;name&gt;</span></code> must be a symbol that labels the first
instruction to execute, and does not need to be previously defined.</p>
<p>Marks the beginning of a list of directives used to generate the bytes of a
kernel descriptor, as described in <a class="reference internal" href="#amdgpu-amdhsa-kernel-descriptor"><span class="std std-ref">Kernel Descriptor</span></a>.
Directives which may appear in this list are described in
<a class="reference internal" href="#amdhsa-kernel-directives-table"><span class="std std-ref">AMDHSA Kernel Assembler Directives</span></a>. Directives may appear in any order, must
be valid for the target being assembled for, and cannot be repeated. Directives
support the range of values specified by the field they reference in
<a class="reference internal" href="#amdgpu-amdhsa-kernel-descriptor"><span class="std std-ref">Kernel Descriptor</span></a>. If a directive is not specified, it is
assumed to have its default value, unless it is marked as “Required”, in which
case it is an error to omit the directive. This list of directives is
terminated by an <code class="docutils literal notranslate"><span class="pre">.end_amdhsa_kernel</span></code> directive.</p>
<blockquote>
<div><table class="docutils align-default" id="amdhsa-kernel-directives-table">
<caption><span class="caption-text">AMDHSA Kernel Assembler Directives</span><a class="headerlink" href="#amdhsa-kernel-directives-table" title="Permalink to this table">¶</a></caption>
<colgroup>
<col style="width: 35%" />
<col style="width: 12%" />
<col style="width: 7%" />
<col style="width: 46%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>Directive</p></th>
<th class="head"><p>Default</p></th>
<th class="head"><p>Supported On</p></th>
<th class="head"><p>Description</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">.amdhsa_group_segment_fixed_size</span></code></p></td>
<td><p>0</p></td>
<td><p>GFX6-GFX10</p></td>
<td><p>Controls GROUP_SEGMENT_FIXED_SIZE in
<a class="reference internal" href="#amdgpu-amdhsa-kernel-descriptor-gfx6-gfx10-table"><span class="std std-ref">Kernel Descriptor for GFX6-GFX10</span></a>.</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">.amdhsa_private_segment_fixed_size</span></code></p></td>
<td><p>0</p></td>
<td><p>GFX6-GFX10</p></td>
<td><p>Controls PRIVATE_SEGMENT_FIXED_SIZE in
<a class="reference internal" href="#amdgpu-amdhsa-kernel-descriptor-gfx6-gfx10-table"><span class="std std-ref">Kernel Descriptor for GFX6-GFX10</span></a>.</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">.amdhsa_user_sgpr_private_segment_buffer</span></code></p></td>
<td><p>0</p></td>
<td><p>GFX6-GFX10</p></td>
<td><p>Controls ENABLE_SGPR_PRIVATE_SEGMENT_BUFFER in
<a class="reference internal" href="#amdgpu-amdhsa-kernel-descriptor-gfx6-gfx10-table"><span class="std std-ref">Kernel Descriptor for GFX6-GFX10</span></a>.</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">.amdhsa_user_sgpr_dispatch_ptr</span></code></p></td>
<td><p>0</p></td>
<td><p>GFX6-GFX10</p></td>
<td><p>Controls ENABLE_SGPR_DISPATCH_PTR in
<a class="reference internal" href="#amdgpu-amdhsa-kernel-descriptor-gfx6-gfx10-table"><span class="std std-ref">Kernel Descriptor for GFX6-GFX10</span></a>.</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">.amdhsa_user_sgpr_queue_ptr</span></code></p></td>
<td><p>0</p></td>
<td><p>GFX6-GFX10</p></td>
<td><p>Controls ENABLE_SGPR_QUEUE_PTR in
<a class="reference internal" href="#amdgpu-amdhsa-kernel-descriptor-gfx6-gfx10-table"><span class="std std-ref">Kernel Descriptor for GFX6-GFX10</span></a>.</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">.amdhsa_user_sgpr_kernarg_segment_ptr</span></code></p></td>
<td><p>0</p></td>
<td><p>GFX6-GFX10</p></td>
<td><p>Controls ENABLE_SGPR_KERNARG_SEGMENT_PTR in
<a class="reference internal" href="#amdgpu-amdhsa-kernel-descriptor-gfx6-gfx10-table"><span class="std std-ref">Kernel Descriptor for GFX6-GFX10</span></a>.</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">.amdhsa_user_sgpr_dispatch_id</span></code></p></td>
<td><p>0</p></td>
<td><p>GFX6-GFX10</p></td>
<td><p>Controls ENABLE_SGPR_DISPATCH_ID in
<a class="reference internal" href="#amdgpu-amdhsa-kernel-descriptor-gfx6-gfx10-table"><span class="std std-ref">Kernel Descriptor for GFX6-GFX10</span></a>.</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">.amdhsa_user_sgpr_flat_scratch_init</span></code></p></td>
<td><p>0</p></td>
<td><p>GFX6-GFX10</p></td>
<td><p>Controls ENABLE_SGPR_FLAT_SCRATCH_INIT in
<a class="reference internal" href="#amdgpu-amdhsa-kernel-descriptor-gfx6-gfx10-table"><span class="std std-ref">Kernel Descriptor for GFX6-GFX10</span></a>.</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">.amdhsa_user_sgpr_private_segment_size</span></code></p></td>
<td><p>0</p></td>
<td><p>GFX6-GFX10</p></td>
<td><p>Controls ENABLE_SGPR_PRIVATE_SEGMENT_SIZE in
<a class="reference internal" href="#amdgpu-amdhsa-kernel-descriptor-gfx6-gfx10-table"><span class="std std-ref">Kernel Descriptor for GFX6-GFX10</span></a>.</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">.amdhsa_wavefront_size32</span></code></p></td>
<td><p>Target
Feature
Specific
(-wavefrontsize64)</p></td>
<td><p>GFX10</p></td>
<td><p>Controls ENABLE_WAVEFRONT_SIZE32 in
<a class="reference internal" href="#amdgpu-amdhsa-kernel-descriptor-gfx6-gfx10-table"><span class="std std-ref">Kernel Descriptor for GFX6-GFX10</span></a>.</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">.amdhsa_system_sgpr_private_segment_wavefront_offset</span></code></p></td>
<td><p>0</p></td>
<td><p>GFX6-GFX10</p></td>
<td><p>Controls ENABLE_SGPR_PRIVATE_SEGMENT_WAVEFRONT_OFFSET in
<a class="reference internal" href="#amdgpu-amdhsa-compute-pgm-rsrc2-gfx6-gfx10-table"><span class="std std-ref">compute_pgm_rsrc2 for GFX6-GFX10</span></a>.</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">.amdhsa_system_sgpr_workgroup_id_x</span></code></p></td>
<td><p>1</p></td>
<td><p>GFX6-GFX10</p></td>
<td><p>Controls ENABLE_SGPR_WORKGROUP_ID_X in
<a class="reference internal" href="#amdgpu-amdhsa-compute-pgm-rsrc2-gfx6-gfx10-table"><span class="std std-ref">compute_pgm_rsrc2 for GFX6-GFX10</span></a>.</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">.amdhsa_system_sgpr_workgroup_id_y</span></code></p></td>
<td><p>0</p></td>
<td><p>GFX6-GFX10</p></td>
<td><p>Controls ENABLE_SGPR_WORKGROUP_ID_Y in
<a class="reference internal" href="#amdgpu-amdhsa-compute-pgm-rsrc2-gfx6-gfx10-table"><span class="std std-ref">compute_pgm_rsrc2 for GFX6-GFX10</span></a>.</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">.amdhsa_system_sgpr_workgroup_id_z</span></code></p></td>
<td><p>0</p></td>
<td><p>GFX6-GFX10</p></td>
<td><p>Controls ENABLE_SGPR_WORKGROUP_ID_Z in
<a class="reference internal" href="#amdgpu-amdhsa-compute-pgm-rsrc2-gfx6-gfx10-table"><span class="std std-ref">compute_pgm_rsrc2 for GFX6-GFX10</span></a>.</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">.amdhsa_system_sgpr_workgroup_info</span></code></p></td>
<td><p>0</p></td>
<td><p>GFX6-GFX10</p></td>
<td><p>Controls ENABLE_SGPR_WORKGROUP_INFO in
<a class="reference internal" href="#amdgpu-amdhsa-compute-pgm-rsrc2-gfx6-gfx10-table"><span class="std std-ref">compute_pgm_rsrc2 for GFX6-GFX10</span></a>.</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">.amdhsa_system_vgpr_workitem_id</span></code></p></td>
<td><p>0</p></td>
<td><p>GFX6-GFX10</p></td>
<td><p>Controls ENABLE_VGPR_WORKITEM_ID in
<a class="reference internal" href="#amdgpu-amdhsa-compute-pgm-rsrc2-gfx6-gfx10-table"><span class="std std-ref">compute_pgm_rsrc2 for GFX6-GFX10</span></a>.
Possible values are defined in
<a class="reference internal" href="#amdgpu-amdhsa-system-vgpr-work-item-id-enumeration-values-table"><span class="std std-ref">System VGPR Work-Item ID Enumeration Values</span></a>.</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">.amdhsa_next_free_vgpr</span></code></p></td>
<td><p>Required</p></td>
<td><p>GFX6-GFX10</p></td>
<td><p>Maximum VGPR number explicitly referenced, plus one.
Used to calculate GRANULATED_WORKITEM_VGPR_COUNT in
<a class="reference internal" href="#amdgpu-amdhsa-compute-pgm-rsrc1-gfx6-gfx10-table"><span class="std std-ref">compute_pgm_rsrc1 for GFX6-GFX10</span></a>.</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">.amdhsa_next_free_sgpr</span></code></p></td>
<td><p>Required</p></td>
<td><p>GFX6-GFX10</p></td>
<td><p>Maximum SGPR number explicitly referenced, plus one.
Used to calculate GRANULATED_WAVEFRONT_SGPR_COUNT in
<a class="reference internal" href="#amdgpu-amdhsa-compute-pgm-rsrc1-gfx6-gfx10-table"><span class="std std-ref">compute_pgm_rsrc1 for GFX6-GFX10</span></a>.</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">.amdhsa_reserve_vcc</span></code></p></td>
<td><p>1</p></td>
<td><p>GFX6-GFX10</p></td>
<td><p>Whether the kernel may use the special VCC SGPR.
Used to calculate GRANULATED_WAVEFRONT_SGPR_COUNT in
<a class="reference internal" href="#amdgpu-amdhsa-compute-pgm-rsrc1-gfx6-gfx10-table"><span class="std std-ref">compute_pgm_rsrc1 for GFX6-GFX10</span></a>.</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">.amdhsa_reserve_flat_scratch</span></code></p></td>
<td><p>1</p></td>
<td><p>GFX7-GFX10</p></td>
<td><p>Whether the kernel may use flat instructions to access
scratch memory. Used to calculate
GRANULATED_WAVEFRONT_SGPR_COUNT in
<a class="reference internal" href="#amdgpu-amdhsa-compute-pgm-rsrc1-gfx6-gfx10-table"><span class="std std-ref">compute_pgm_rsrc1 for GFX6-GFX10</span></a>.</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">.amdhsa_reserve_xnack_mask</span></code></p></td>
<td><p>Target
Feature
Specific
(+xnack)</p></td>
<td><p>GFX8-GFX10</p></td>
<td><p>Whether the kernel may trigger XNACK replay.
Used to calculate GRANULATED_WAVEFRONT_SGPR_COUNT in
<a class="reference internal" href="#amdgpu-amdhsa-compute-pgm-rsrc1-gfx6-gfx10-table"><span class="std std-ref">compute_pgm_rsrc1 for GFX6-GFX10</span></a>.</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">.amdhsa_float_round_mode_32</span></code></p></td>
<td><p>0</p></td>
<td><p>GFX6-GFX10</p></td>
<td><p>Controls FLOAT_ROUND_MODE_32 in
<a class="reference internal" href="#amdgpu-amdhsa-compute-pgm-rsrc1-gfx6-gfx10-table"><span class="std std-ref">compute_pgm_rsrc1 for GFX6-GFX10</span></a>.
Possible values are defined in
<a class="reference internal" href="#amdgpu-amdhsa-floating-point-rounding-mode-enumeration-values-table"><span class="std std-ref">Floating Point Rounding Mode Enumeration Values</span></a>.</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">.amdhsa_float_round_mode_16_64</span></code></p></td>
<td><p>0</p></td>
<td><p>GFX6-GFX10</p></td>
<td><p>Controls FLOAT_ROUND_MODE_16_64 in
<a class="reference internal" href="#amdgpu-amdhsa-compute-pgm-rsrc1-gfx6-gfx10-table"><span class="std std-ref">compute_pgm_rsrc1 for GFX6-GFX10</span></a>.
Possible values are defined in
<a class="reference internal" href="#amdgpu-amdhsa-floating-point-rounding-mode-enumeration-values-table"><span class="std std-ref">Floating Point Rounding Mode Enumeration Values</span></a>.</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">.amdhsa_float_denorm_mode_32</span></code></p></td>
<td><p>0</p></td>
<td><p>GFX6-GFX10</p></td>
<td><p>Controls FLOAT_DENORM_MODE_32 in
<a class="reference internal" href="#amdgpu-amdhsa-compute-pgm-rsrc1-gfx6-gfx10-table"><span class="std std-ref">compute_pgm_rsrc1 for GFX6-GFX10</span></a>.
Possible values are defined in
<a class="reference internal" href="#amdgpu-amdhsa-floating-point-denorm-mode-enumeration-values-table"><span class="std std-ref">Floating Point Denorm Mode Enumeration Values</span></a>.</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">.amdhsa_float_denorm_mode_16_64</span></code></p></td>
<td><p>3</p></td>
<td><p>GFX6-GFX10</p></td>
<td><p>Controls FLOAT_DENORM_MODE_16_64 in
<a class="reference internal" href="#amdgpu-amdhsa-compute-pgm-rsrc1-gfx6-gfx10-table"><span class="std std-ref">compute_pgm_rsrc1 for GFX6-GFX10</span></a>.
Possible values are defined in
<a class="reference internal" href="#amdgpu-amdhsa-floating-point-denorm-mode-enumeration-values-table"><span class="std std-ref">Floating Point Denorm Mode Enumeration Values</span></a>.</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">.amdhsa_dx10_clamp</span></code></p></td>
<td><p>1</p></td>
<td><p>GFX6-GFX10</p></td>
<td><p>Controls ENABLE_DX10_CLAMP in
<a class="reference internal" href="#amdgpu-amdhsa-compute-pgm-rsrc1-gfx6-gfx10-table"><span class="std std-ref">compute_pgm_rsrc1 for GFX6-GFX10</span></a>.</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">.amdhsa_ieee_mode</span></code></p></td>
<td><p>1</p></td>
<td><p>GFX6-GFX10</p></td>
<td><p>Controls ENABLE_IEEE_MODE in
<a class="reference internal" href="#amdgpu-amdhsa-compute-pgm-rsrc1-gfx6-gfx10-table"><span class="std std-ref">compute_pgm_rsrc1 for GFX6-GFX10</span></a>.</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">.amdhsa_fp16_overflow</span></code></p></td>
<td><p>0</p></td>
<td><p>GFX9-GFX10</p></td>
<td><p>Controls FP16_OVFL in
<a class="reference internal" href="#amdgpu-amdhsa-compute-pgm-rsrc1-gfx6-gfx10-table"><span class="std std-ref">compute_pgm_rsrc1 for GFX6-GFX10</span></a>.</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">.amdhsa_workgroup_processor_mode</span></code></p></td>
<td><p>Target
Feature
Specific
(-cumode)</p></td>
<td><p>GFX10</p></td>
<td><p>Controls ENABLE_WGP_MODE in
<a class="reference internal" href="#amdgpu-amdhsa-kernel-descriptor-gfx6-gfx10-table"><span class="std std-ref">Kernel Descriptor for GFX6-GFX10</span></a>.</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">.amdhsa_memory_ordered</span></code></p></td>
<td><p>1</p></td>
<td><p>GFX10</p></td>
<td><p>Controls MEM_ORDERED in
<a class="reference internal" href="#amdgpu-amdhsa-compute-pgm-rsrc1-gfx6-gfx10-table"><span class="std std-ref">compute_pgm_rsrc1 for GFX6-GFX10</span></a>.</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">.amdhsa_forward_progress</span></code></p></td>
<td><p>0</p></td>
<td><p>GFX10</p></td>
<td><p>Controls FWD_PROGRESS in
<a class="reference internal" href="#amdgpu-amdhsa-compute-pgm-rsrc1-gfx6-gfx10-table"><span class="std std-ref">compute_pgm_rsrc1 for GFX6-GFX10</span></a>.</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">.amdhsa_exception_fp_ieee_invalid_op</span></code></p></td>
<td><p>0</p></td>
<td><p>GFX6-GFX10</p></td>
<td><p>Controls ENABLE_EXCEPTION_IEEE_754_FP_INVALID_OPERATION in
<a class="reference internal" href="#amdgpu-amdhsa-compute-pgm-rsrc2-gfx6-gfx10-table"><span class="std std-ref">compute_pgm_rsrc2 for GFX6-GFX10</span></a>.</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">.amdhsa_exception_fp_denorm_src</span></code></p></td>
<td><p>0</p></td>
<td><p>GFX6-GFX10</p></td>
<td><p>Controls ENABLE_EXCEPTION_FP_DENORMAL_SOURCE in
<a class="reference internal" href="#amdgpu-amdhsa-compute-pgm-rsrc2-gfx6-gfx10-table"><span class="std std-ref">compute_pgm_rsrc2 for GFX6-GFX10</span></a>.</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">.amdhsa_exception_fp_ieee_div_zero</span></code></p></td>
<td><p>0</p></td>
<td><p>GFX6-GFX10</p></td>
<td><p>Controls ENABLE_EXCEPTION_IEEE_754_FP_DIVISION_BY_ZERO in
<a class="reference internal" href="#amdgpu-amdhsa-compute-pgm-rsrc2-gfx6-gfx10-table"><span class="std std-ref">compute_pgm_rsrc2 for GFX6-GFX10</span></a>.</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">.amdhsa_exception_fp_ieee_overflow</span></code></p></td>
<td><p>0</p></td>
<td><p>GFX6-GFX10</p></td>
<td><p>Controls ENABLE_EXCEPTION_IEEE_754_FP_OVERFLOW in
<a class="reference internal" href="#amdgpu-amdhsa-compute-pgm-rsrc2-gfx6-gfx10-table"><span class="std std-ref">compute_pgm_rsrc2 for GFX6-GFX10</span></a>.</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">.amdhsa_exception_fp_ieee_underflow</span></code></p></td>
<td><p>0</p></td>
<td><p>GFX6-GFX10</p></td>
<td><p>Controls ENABLE_EXCEPTION_IEEE_754_FP_UNDERFLOW in
<a class="reference internal" href="#amdgpu-amdhsa-compute-pgm-rsrc2-gfx6-gfx10-table"><span class="std std-ref">compute_pgm_rsrc2 for GFX6-GFX10</span></a>.</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">.amdhsa_exception_fp_ieee_inexact</span></code></p></td>
<td><p>0</p></td>
<td><p>GFX6-GFX10</p></td>
<td><p>Controls ENABLE_EXCEPTION_IEEE_754_FP_INEXACT in
<a class="reference internal" href="#amdgpu-amdhsa-compute-pgm-rsrc2-gfx6-gfx10-table"><span class="std std-ref">compute_pgm_rsrc2 for GFX6-GFX10</span></a>.</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">.amdhsa_exception_int_div_zero</span></code></p></td>
<td><p>0</p></td>
<td><p>GFX6-GFX10</p></td>
<td><p>Controls ENABLE_EXCEPTION_INT_DIVIDE_BY_ZERO in
<a class="reference internal" href="#amdgpu-amdhsa-compute-pgm-rsrc2-gfx6-gfx10-table"><span class="std std-ref">compute_pgm_rsrc2 for GFX6-GFX10</span></a>.</p></td>
</tr>
</tbody>
</table>
</div></blockquote>
</div>
<div class="section" id="amdgpu-metadata">
<h5><a class="toc-backref" href="#id133">.amdgpu_metadata</a><a class="headerlink" href="#amdgpu-metadata" title="Permalink to this headline">¶</a></h5>
<p>Optional directive which declares the contents of the <code class="docutils literal notranslate"><span class="pre">NT_AMDGPU_METADATA</span></code>
note record (see <a class="reference internal" href="#amdgpu-elf-note-records-table-v3"><span class="std std-ref">AMDGPU Code Object V3 ELF Note Records</span></a>).</p>
<p>The contents must be in the <a class="reference internal" href="#yaml" id="id45"><span>[YAML]</span></a> markup format, with the same structure and
semantics described in <a class="reference internal" href="#amdgpu-amdhsa-code-object-metadata-v3"><span class="std std-ref">Code Object V3 Metadata (-mattr=+code-object-v3)</span></a>.</p>
<p>This directive is terminated by an <code class="docutils literal notranslate"><span class="pre">.end_amdgpu_metadata</span></code> directive.</p>
</div>
</div>
<div class="section" id="code-object-v3-example-source-code-mattr-code-object-v3">
<span id="amdgpu-amdhsa-assembler-example-v3"></span><h4><a class="toc-backref" href="#id134">Code Object V3 Example Source Code (-mattr=+code-object-v3)</a><a class="headerlink" href="#code-object-v3-example-source-code-mattr-code-object-v3" title="Permalink to this headline">¶</a></h4>
<p>Here is an example of a minimal assembly source file, defining one HSA kernel:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>.amdgcn_target &quot;amdgcn-amd-amdhsa--gfx900+xnack&quot; // optional

.text
.globl hello_world
.p2align 8
.type hello_world,@function
hello_world:
  s_load_dwordx2 s[0:1], s[0:1] 0x0
  v_mov_b32 v0, 3.14159
  s_waitcnt lgkmcnt(0)
  v_mov_b32 v1, s0
  v_mov_b32 v2, s1
  flat_store_dword v[1:2], v0
  s_endpgm
.Lfunc_end0:
  .size   hello_world, .Lfunc_end0-hello_world

.rodata
.p2align 6
.amdhsa_kernel hello_world
  .amdhsa_user_sgpr_kernarg_segment_ptr 1
  .amdhsa_next_free_vgpr .amdgcn.next_free_vgpr
  .amdhsa_next_free_sgpr .amdgcn.next_free_sgpr
.end_amdhsa_kernel

.amdgpu_metadata
---
amdhsa.version:
  - 1
  - 0
amdhsa.kernels:
  - .name: hello_world
    .symbol: hello_world.kd
    .kernarg_segment_size: 48
    .group_segment_fixed_size: 0
    .private_segment_fixed_size: 0
    .kernarg_segment_align: 4
    .wavefront_size: 64
    .sgpr_count: 2
    .vgpr_count: 3
    .max_flat_workgroup_size: 256
...
.end_amdgpu_metadata
</pre></div>
</div>
<p>If an assembly source file contains multiple kernels and/or functions, the
<a class="reference internal" href="#amdgpu-amdhsa-assembler-symbol-next-free-vgpr"><span class="std std-ref">.amdgcn.next_free_vgpr</span></a> and
<a class="reference internal" href="#amdgpu-amdhsa-assembler-symbol-next-free-sgpr"><span class="std std-ref">.amdgcn.next_free_sgpr</span></a> symbols may be reset using
the <code class="docutils literal notranslate"><span class="pre">.set</span> <span class="pre">&lt;symbol&gt;,</span> <span class="pre">&lt;expression&gt;</span></code> directive. For example, in the case of two
kernels, where <code class="docutils literal notranslate"><span class="pre">function1</span></code> is only called from <code class="docutils literal notranslate"><span class="pre">kernel1</span></code> it is sufficient
to group the function with the kernel that calls it and reset the symbols
between the two connected components:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>.amdgcn_target &quot;amdgcn-amd-amdhsa--gfx900+xnack&quot; // optional

// gpr tracking symbols are implicitly set to zero

.text
.globl kern0
.p2align 8
.type kern0,@function
kern0:
  // ...
  s_endpgm
.Lkern0_end:
  .size   kern0, .Lkern0_end-kern0

.rodata
.p2align 6
.amdhsa_kernel kern0
  // ...
  .amdhsa_next_free_vgpr .amdgcn.next_free_vgpr
  .amdhsa_next_free_sgpr .amdgcn.next_free_sgpr
.end_amdhsa_kernel

// reset symbols to begin tracking usage in func1 and kern1
.set .amdgcn.next_free_vgpr, 0
.set .amdgcn.next_free_sgpr, 0

.text
.hidden func1
.global func1
.p2align 2
.type func1,@function
func1:
  // ...
  s_setpc_b64 s[30:31]
.Lfunc1_end:
.size func1, .Lfunc1_end-func1

.globl kern1
.p2align 8
.type kern1,@function
kern1:
  // ...
  s_getpc_b64 s[4:5]
  s_add_u32 s4, s4, func1@rel32@lo+4
  s_addc_u32 s5, s5, func1@rel32@lo+4
  s_swappc_b64 s[30:31], s[4:5]
  // ...
  s_endpgm
.Lkern1_end:
  .size   kern1, .Lkern1_end-kern1

.rodata
.p2align 6
.amdhsa_kernel kern1
  // ...
  .amdhsa_next_free_vgpr .amdgcn.next_free_vgpr
  .amdhsa_next_free_sgpr .amdgcn.next_free_sgpr
.end_amdhsa_kernel
</pre></div>
</div>
<p>These symbols cannot identify connected components in order to automatically
track the usage for each kernel. However, in some cases careful organization of
the kernels and functions in the source file means there is minimal additional
effort required to accurately calculate GPR usage.</p>
</div>
</div>
</div>
<div class="section" id="additional-documentation">
<h2><a class="toc-backref" href="#id135">Additional Documentation</a><a class="headerlink" href="#additional-documentation" title="Permalink to this headline">¶</a></h2>
<dl class="citation">
<dt class="label" id="amd-radeon-hd-2000-3000"><span class="brackets"><a class="fn-backref" href="#id3">AMD-RADEON-HD-2000-3000</a></span></dt>
<dd><p><a class="reference external" href="http://developer.amd.com/wordpress/media/2012/10/R600_Instruction_Set_Architecture.pdf">AMD R6xx shader ISA</a></p>
</dd>
<dt class="label" id="amd-radeon-hd-4000"><span class="brackets"><a class="fn-backref" href="#id4">AMD-RADEON-HD-4000</a></span></dt>
<dd><p><a class="reference external" href="http://developer.amd.com/wordpress/media/2012/10/R700-Family_Instruction_Set_Architecture.pdf">AMD R7xx shader ISA</a></p>
</dd>
<dt class="label" id="amd-radeon-hd-5000"><span class="brackets"><a class="fn-backref" href="#id5">AMD-RADEON-HD-5000</a></span></dt>
<dd><p><a class="reference external" href="http://developer.amd.com/wordpress/media/2012/10/AMD_Evergreen-Family_Instruction_Set_Architecture.pdf">AMD Evergreen shader ISA</a></p>
</dd>
<dt class="label" id="amd-radeon-hd-6000"><span class="brackets"><a class="fn-backref" href="#id6">AMD-RADEON-HD-6000</a></span></dt>
<dd><p><a class="reference external" href="http://developer.amd.com/wordpress/media/2012/10/AMD_HD_6900_Series_Instruction_Set_Architecture.pdf">AMD Cayman/Trinity shader ISA</a></p>
</dd>
<dt class="label" id="amd-gcn-gfx6"><span class="brackets">AMD-GCN-GFX6</span><span class="fn-backref">(<a href="#id7">1</a>,<a href="#id40">2</a>)</span></dt>
<dd><p><a class="reference external" href="http://developer.amd.com/wordpress/media/2012/12/AMD_Southern_Islands_Instruction_Set_Architecture.pdf">AMD Southern Islands Series ISA</a></p>
</dd>
<dt class="label" id="amd-gcn-gfx7"><span class="brackets">AMD-GCN-GFX7</span><span class="fn-backref">(<a href="#id8">1</a>,<a href="#id41">2</a>)</span></dt>
<dd><p><a class="reference external" href="http://developer.amd.com/wordpress/media/2013/07/AMD_Sea_Islands_Instruction_Set_Architecture.pdf">AMD Sea Islands Series ISA</a></p>
</dd>
<dt class="label" id="amd-gcn-gfx8"><span class="brackets">AMD-GCN-GFX8</span><span class="fn-backref">(<a href="#id9">1</a>,<a href="#id42">2</a>)</span></dt>
<dd><p><a class="reference external" href="http://amd-dev.wpengine.netdna-cdn.com/wordpress/media/2013/12/AMD_GCN3_Instruction_Set_Architecture_rev1.1.pdf">AMD GCN3 Instruction Set Architecture</a></p>
</dd>
<dt class="label" id="amd-gcn-gfx9"><span class="brackets">AMD-GCN-GFX9</span><span class="fn-backref">(<a href="#id10">1</a>,<a href="#id43">2</a>)</span></dt>
<dd><p><a class="reference external" href="http://developer.amd.com/wordpress/media/2013/12/Vega_Shader_ISA_28July2017.pdf">AMD “Vega” Instruction Set Architecture</a></p>
</dd>
<dt class="label" id="amd-gcn-gfx10"><span class="brackets">AMD-GCN-GFX10</span><span class="fn-backref">(<a href="#id11">1</a>,<a href="#id44">2</a>)</span></dt>
<dd><p>AMD “Navi” Instruction Set Architecture <em>TBA</em></p>
</dd>
</dl>
<dl class="citation">
<dt class="label" id="amd-rocm"><span class="brackets">AMD-ROCm</span><span class="fn-backref">(<a href="#id2">1</a>,<a href="#id22">2</a>,<a href="#id27">3</a>,<a href="#id38">4</a>)</span></dt>
<dd><p><a class="reference external" href="http://gpuopen.com/compute-product/rocm/">ROCm: Open Platform for Development, Discovery and Education Around GPU Computing</a></p>
</dd>
<dt class="label" id="amd-rocm-github"><span class="brackets">AMD-ROCm-github</span><span class="fn-backref">(<a href="#id33">1</a>,<a href="#id34">2</a>)</span></dt>
<dd><p><a class="reference external" href="http://github.com/RadeonOpenCompute">ROCm github</a></p>
</dd>
<dt class="label" id="hsa"><span class="brackets">HSA</span><span class="fn-backref">(<a href="#id1">1</a>,<a href="#id12">2</a>,<a href="#id21">3</a>,<a href="#id26">4</a>,<a href="#id30">5</a>,<a href="#id31">6</a>,<a href="#id32">7</a>,<a href="#id35">8</a>,<a href="#id37">9</a>)</span></dt>
<dd><p><a class="reference external" href="http://www.hsafoundation.com/">Heterogeneous System Architecture (HSA) Foundation</a></p>
</dd>
<dt class="label" id="elf"><span class="brackets">ELF</span><span class="fn-backref">(<a href="#id19">1</a>,<a href="#id20">2</a>)</span></dt>
<dd><p><a class="reference external" href="http://www.sco.com/developers/gabi/">Executable and Linkable Format (ELF)</a></p>
</dd>
<dt class="label" id="id46"><span class="brackets"><a class="fn-backref" href="#id25">DWARF</a></span></dt>
<dd><p><a class="reference external" href="http://dwarfstd.org/">DWARF Debugging Information Format</a></p>
</dd>
<dt class="label" id="yaml"><span class="brackets">YAML</span><span class="fn-backref">(<a href="#id28">1</a>,<a href="#id45">2</a>)</span></dt>
<dd><p><a class="reference external" href="http://www.yaml.org/spec/1.2/spec.html">YAML Ain’t Markup Language (YAML™) Version 1.2</a></p>
</dd>
<dt class="label" id="msgpack"><span class="brackets">MsgPack</span><span class="fn-backref">(<a href="#id23">1</a>,<a href="#id24">2</a>,<a href="#id29">3</a>)</span></dt>
<dd><p><a class="reference external" href="http://www.msgpack.org/">Message Pack</a></p>
</dd>
<dt class="label" id="id47"><span class="brackets">OpenCL</span><span class="fn-backref">(<a href="#id14">1</a>,<a href="#id36">2</a>)</span></dt>
<dd><p><a class="reference external" href="http://www.khronos.org/registry/cl/specs/opencl-2.0.pdf">The OpenCL Specification Version 2.0</a></p>
</dd>
<dt class="label" id="hrf"><span class="brackets"><a class="fn-backref" href="#id13">HRF</a></span></dt>
<dd><p><a class="reference external" href="http://benedictgaster.org/wp-content/uploads/2014/01/asplos269-FINAL.pdf">Heterogeneous-race-free Memory Models</a></p>
</dd>
<dt class="label" id="clang-attr"><span class="brackets">CLANG-ATTR</span><span class="fn-backref">(<a href="#id15">1</a>,<a href="#id16">2</a>,<a href="#id17">3</a>,<a href="#id18">4</a>)</span></dt>
<dd><p><a class="reference external" href="http://clang.llvm.org/docs/AttributeReference.html">Attributes in Clang</a></p>
</dd>
</dl>
</div>
</div>


            <div class="clearer"></div>
          </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="AMDGPU/AMDGPUAsmGFX7.html" title="Syntax of GFX7 Instructions"
             >next</a> |</li>
        <li class="right" >
          <a href="NVPTXUsage.html" title="User Guide for NVPTX Back-end"
             >previous</a> |</li>
  <li><a href="http://llvm.org/">LLVM Home</a>&nbsp;|&nbsp;</li>
  <li><a href="index.html">Documentation</a>&raquo;</li>

        <li class="nav-item nav-item-this"><a href="">User Guide for AMDGPU Backend</a></li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &#169; Copyright 2003-2020, LLVM Project.
      Last updated on 2020-09-20.
      Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.2.1.
    </div>
  </body>
</html>